Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Solution PR#42560 + Partial solution to PR#42453


Core:
        - Added references to variables in solution of bug#42453:_expression_ result types not computed
        - Solution to bug#42560: Class Cast Exception during Method definition
Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group


Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/ChangeLog,v
retrieving revision 1.141
diff -u -r1.141 ChangeLog
--- ChangeLog	4 Sep 2003 15:37:20 -0000	1.141
+++ ChangeLog	4 Sep 2003 20:35:32 -0000
@@ -1,3 +1,7 @@
+2003-09-04 Hoda Amer
+	- Added references to variables in solution of bug#42453:Expression result types not computed
+	- Solution to bug#42560: Class Cast Exception during Method definition
+	
 2003-09-04 Alain Magloire
 
 	The IProgressMonitor.setCancelled() is incorrect, it tries to access
@@ -16,7 +20,7 @@
 	whole ITOkenDuple for the typeId instead of just the string.
 	- Changed the ASTExpression in both quick and complete packages and
 	deleted the "id" parameter.
-	- Added partial solution to bug #42453: Exception result types not computed.
+	- Added partial solution to bug #42453:Expression result types not computed.
 	Now they are computed for simple types only.
 	
 2003-09-03 David Inglis
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.25
diff -u -r1.25 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	4 Sep 2003 14:39:15 -0000	1.25
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	4 Sep 2003 20:35:35 -0000
@@ -60,6 +60,7 @@
 import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
 import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
 import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
+import org.eclipse.cdt.internal.core.parser.ast.ASTParameterDeclaration;
 import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
 import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension;
 import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
@@ -710,8 +711,10 @@
         IContainerSymbol startingScope = scopeToSymbol( scope );
                 
         //look up typeId & add to references
-        if( typeId != null )
-        	lookupQualifiedName( startingScope, typeId, references, false );
+		ISymbol symbol = null;
+        if( typeId != null ){
+			 symbol = lookupQualifiedName( startingScope, typeId, references, false );
+        }
 		
 		if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){        							
 			ITokenDuple functionId = ((ASTExpression)lhs).getTypeId();
@@ -722,12 +725,12 @@
         ASTExpression expression =  new ASTExpression( kind, lhs, rhs, thirdExpression, 
         							typeId,	literal, newDescriptor, references);
 		       							
-		expression.setResultType (getExpressionResultType(expression));
+		expression.setResultType (getExpressionResultType(expression, symbol));
         							
         return expression;
     }
 
-	protected List getExpressionResultType(IASTExpression expression){
+	protected List getExpressionResultType(IASTExpression expression, ISymbol symbol){
 		List result = new ArrayList();
 		
 		if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY) {
@@ -760,6 +763,14 @@
 			result.add(info);
 			return result;
 		}
+		if (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION){
+			TypeInfo info = new TypeInfo();
+			info.setType(TypeInfo.t_type);
+			if(symbol != null)
+				info.setTypeSymbol(symbol);			
+			result.add(info);
+			return result;
+		}
 		if ((expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS) 
 		|| (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) ){
 			ASTExpression right = (ASTExpression)expression.getLHSExpression();
@@ -1004,8 +1015,16 @@
 			if((parentScope != null) && (parentScope.getType() == TypeInfo.t_class)){
 				// find out the visibility of the method's declaration
 				List functionReferences = new ArrayList();
+				List functionParameters = new LinkedList();
+				// the lookup requires a list of type infos
+				// instead of a list of IASTParameterDeclaration
+				Iterator p = parameters.iterator();
+				while (p.hasNext()){
+					ASTParameterDeclaration param = (ASTParameterDeclaration)p.next();
+					functionParameters.add(getParameterTypeInfo(param));
+				}
 				IParameterizedSymbol methodDeclaration = 
-					(IParameterizedSymbol) lookupQualifiedName(parentScope, functionName, TypeInfo.t_function, parameters, 0, functionReferences, false);
+					(IParameterizedSymbol) lookupQualifiedName(parentScope, functionName, TypeInfo.t_function, functionParameters, 0, functionReferences, false);
 				if(methodDeclaration != null){
 					ASTMethodReference reference = (ASTMethodReference) functionReferences.iterator().next();
 				visibility = ((IASTMethod)reference.getReferencedElement()).getVisiblity();		
@@ -1066,92 +1085,108 @@
         }
     }
 
-    /**
-     * @param symbol
-     * @param returnType
-     */
-    protected void setParameter(IParameterizedSymbol symbol, IASTAbstractDeclaration absDecl, boolean isParameter, List references) throws ASTSemanticException
-    {
-    	if (absDecl.getTypeSpecifier() == null)
-    		return;
-    		
-    	TypeInfo.eType type = null;
-    	ISymbol xrefSymbol = null;
-    	List newReferences = null; 
-        if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) 
-        {
-        	IASTSimpleTypeSpecifier.Type kind = ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType();
-        	if( kind == IASTSimpleTypeSpecifier.Type.BOOL )
-        		type = TypeInfo.t_bool;
-        	else if( kind == IASTSimpleTypeSpecifier.Type.CHAR )
-        		type = TypeInfo.t_char;
-        	else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE )
-        		type = TypeInfo.t_double;
-        	else if( kind == IASTSimpleTypeSpecifier.Type.FLOAT )
-        		type = TypeInfo.t_float; 
-        	else if( kind == IASTSimpleTypeSpecifier.Type.INT )
-        		type = TypeInfo.t_int;
-        	else if( kind == IASTSimpleTypeSpecifier.Type.VOID )
-        		type = TypeInfo.t_void;
-        	else if( kind == IASTSimpleTypeSpecifier.Type.WCHAR_T)
-        		type = TypeInfo.t_wchar_t;
-        	else if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
-        	{
-        		type = TypeInfo.t_type;
-        		xrefSymbol = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getSymbol(); 
-        		newReferences = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getReferences();
-        	}
-        	else
-        		throw new ASTSemanticException(); 
-        }
-        else if( absDecl.getTypeSpecifier() instanceof IASTClassSpecifier )
-        {
-        	ASTClassKind kind = ((IASTClassSpecifier)absDecl.getTypeSpecifier()).getClassKind();
-        	if( kind == ASTClassKind.CLASS )
-        		type = TypeInfo.t_class;
-        	else if( kind == ASTClassKind.STRUCT )
-				type = TypeInfo.t_struct;
+	protected TypeInfo getParameterTypeInfo( IASTAbstractDeclaration absDecl)throws ASTSemanticException{
+		TypeInfo type = new TypeInfo();
+		if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) 
+		{
+			IASTSimpleTypeSpecifier.Type kind = ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType();
+			if( kind == IASTSimpleTypeSpecifier.Type.BOOL )
+				type.setType(TypeInfo.t_bool);
+			else if( kind == IASTSimpleTypeSpecifier.Type.CHAR )
+				type.setType(TypeInfo.t_char);
+			else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE )
+				type.setType(TypeInfo.t_double);
+			else if( kind == IASTSimpleTypeSpecifier.Type.FLOAT )
+				type.setType(TypeInfo.t_float); 
+			else if( kind == IASTSimpleTypeSpecifier.Type.INT )
+				type.setType(TypeInfo.t_int);
+			else if( kind == IASTSimpleTypeSpecifier.Type.VOID )
+				type.setType(TypeInfo.t_void);
+			else if( kind == IASTSimpleTypeSpecifier.Type.WCHAR_T)
+				type.setType(TypeInfo.t_wchar_t);
+			else if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
+				type.setType(TypeInfo.t_type);
+			else
+				throw new ASTSemanticException(); 
+		}
+		else if( absDecl.getTypeSpecifier() instanceof IASTClassSpecifier )
+		{
+			ASTClassKind kind = ((IASTClassSpecifier)absDecl.getTypeSpecifier()).getClassKind();
+			if( kind == ASTClassKind.CLASS )
+				type.setType(TypeInfo.t_class);
+			else if( kind == ASTClassKind.STRUCT )
+				type.setType(TypeInfo.t_struct);
 			else if( kind == ASTClassKind.UNION )
-				type = TypeInfo.t_union;
+				type.setType(TypeInfo.t_union);
 			else
 				throw new ASTSemanticException();
-        }
-        else if( absDecl.getTypeSpecifier() instanceof IASTEnumerationSpecifier )
-        {
-        	type = TypeInfo.t_enumeration;
-        }
-        else if( absDecl.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier )
-        {
+		}
+		else if( absDecl.getTypeSpecifier() instanceof IASTEnumerationSpecifier )
+		{
+			type.setType(TypeInfo.t_enumeration);
+		}
+		else if( absDecl.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier )
+		{
 			ASTClassKind kind = ((IASTElaboratedTypeSpecifier)absDecl.getTypeSpecifier()).getClassKind();
 			if( kind == ASTClassKind.CLASS )
-				type = TypeInfo.t_class;
+				type.setType(TypeInfo.t_class);
 			else if( kind == ASTClassKind.STRUCT )
-				type = TypeInfo.t_struct;
+				type.setType(TypeInfo.t_struct);
 			else if( kind == ASTClassKind.UNION )
-				type = TypeInfo.t_union;
+				type.setType(TypeInfo.t_union);
 			else if( kind == ASTClassKind.ENUM )
-				type = TypeInfo.t_enumeration;
+				type.setType(TypeInfo.t_enumeration);
 			else
 				throw new ASTSemanticException();
-        }
-        else
-        	throw new ASTSemanticException(); 
-        
-        ISymbol paramSymbol = pst.newSymbol( "", type );
-        if( xrefSymbol != null )
-        	paramSymbol.setTypeSymbol( xrefSymbol );
-        
-        setPointerOperators( paramSymbol, absDecl.getPointerOperators(), absDecl.getArrayModifiers() );
-
-        if( isParameter)
-        	symbol.addParameter( paramSymbol );
-        else
+		}
+		else
+			throw new ASTSemanticException(); 		
+		return type;		
+	}
+    /**
+	 * @param symbol
+	 * @param returnType
+	 */
+	protected void setParameter(IParameterizedSymbol symbol, IASTAbstractDeclaration absDecl, boolean isParameter, List references) throws ASTSemanticException
+	{
+		if (absDecl.getTypeSpecifier() == null)
+			return;
+	
+		// now determined by another function    		
+		TypeInfo.eType type = getParameterTypeInfo(absDecl).getType();
+		
+		ISymbol xrefSymbol = null;
+		List newReferences = null; 
+	    if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) 
+	    {
+	    	IASTSimpleTypeSpecifier.Type kind = ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType();
+	   		if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
+	    	{
+	    		xrefSymbol = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getSymbol(); 
+	    		newReferences = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getReferences();
+	    	}
+	    }
+	    
+	    String paramName = "";
+	    if(absDecl instanceof IASTParameterDeclaration){
+	    	paramName = ((IASTParameterDeclaration)absDecl).getName();
+	    }
+	    
+	    ISymbol paramSymbol = pst.newSymbol( paramName, type );
+	    if( xrefSymbol != null )
+	    	paramSymbol.setTypeSymbol( xrefSymbol.getTypeSymbol() );
+	    
+	    setPointerOperators( paramSymbol, absDecl.getPointerOperators(), absDecl.getArrayModifiers() );
+	
+	    if( isParameter)
+	    	symbol.addParameter( paramSymbol );
+	    else
 			symbol.setReturnType( paramSymbol );
 			
 		if( newReferences != null )
 			references.addAll( newReferences );
 		
-    }
+	}
 
     /**
      * @param paramSymbol
@@ -1376,13 +1411,10 @@
         	symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
             references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() );
         }
-        else if( abstractDeclaration.getTypeSpecifier() instanceof ASTClassSpecifier )
+        else if(( abstractDeclaration.getTypeSpecifier() instanceof ASTClassSpecifier ) ||
+		( abstractDeclaration.getTypeSpecifier() instanceof ASTElaboratedTypeSpecifier )) 
         {
-        	symbolToBeCloned = ((ASTClassSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
-        }
-		else if( abstractDeclaration.getTypeSpecifier() instanceof ASTElaboratedTypeSpecifier )
-		{
-			symbolToBeCloned = ((ASTElaboratedTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
+            symbolToBeCloned = pst.newSymbol(name, TypeInfo.t_type);
 		}
 		newSymbol = (ISymbol) symbolToBeCloned.clone(); 
 		newSymbol.setName( name );

Back to the top