public override void VisitReturnStatement(ReturnStatementSyntax node) { if (node.Expression == null) { return; } var nodeSymbol = GetNodeSymbol(node.Expression); if (nodeSymbol != null) { SyntaxNode returningPoint = node; while (returningPoint != null && !((returningPoint is BaseMethodDeclarationSyntax) || (returningPoint is AccessorDeclarationSyntax) || (returningPoint is AnonymousFunctionExpressionSyntax))) { returningPoint = returningPoint.Parent; } AbstractNode returningNode; if (returningPoint is BaseMethodDeclarationSyntax || returningPoint is AnonymousFunctionExpressionSyntax) { var methodSymbol = (_semanticModel.GetDeclaredSymbol(returningPoint) ?? _semanticModel.GetSymbolInfo(returningPoint).Symbol) as IMethodSymbol; returningNode = new MethodReturnSymbol(methodSymbol); } else if (returningPoint is AccessorDeclarationSyntax) { var propertySymbol = _semanticModel.GetDeclaredSymbol(returningPoint.Parent.Parent); returningNode = new VariableSymbol(propertySymbol); } else { throw new Exception("Never Happens"); } AddSubtypingRelation(returningNode, nodeSymbol); } base.VisitReturnStatement(node); }
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node) { base.VisitAssignmentExpression(node); var rightSymbol = _semanticModel.GetSymbolInfo(node.Right).Symbol; if (node.Left is ElementAccessExpressionSyntax) { // TODO } else { var leftSymbol = _semanticModel.GetSymbolInfo(node.Left).Symbol; if (!IsUsedSymbol(leftSymbol) || !IsUsedSymbol(rightSymbol)) { return; } var constValue = _semanticModel.GetConstantValue(node.Right); if (rightSymbol != null && leftSymbol != null) // rightSymbol may be null if we have a boolean expression { AbstractNode rightSymbolNode; if (rightSymbol is IMethodSymbol) { rightSymbolNode = new MethodReturnSymbol(rightSymbol as IMethodSymbol); } else { rightSymbolNode = new VariableSymbol(rightSymbol); } AddSubtypingRelation(new VariableSymbol(leftSymbol), rightSymbolNode); } else if (constValue.HasValue && leftSymbol != null) { AddSubtypingRelation(new VariableSymbol(leftSymbol), new LiteralSymbol(constValue.Value, node.GetLocation())); } } }