private void ResolveDefault( ParserRuleContext expression, StatementResolutionContext statementContext = StatementResolutionContext.Undefined, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false, bool isSetAssignment = false) { var withExpression = GetInnerMostWithExpression(); var boundExpression = _bindingService.ResolveDefault( _moduleDeclaration, _currentParent, expression, withExpression, statementContext); if (boundExpression.Classification == ExpressionClassification.ResolutionFailed) { var lexpression = expression as VBAParser.LExpressionContext ?? expression.GetChild <VBAParser.LExpressionContext>(0) ?? (expression as VBAParser.LExprContext ?? expression.GetChild <VBAParser.LExprContext>(0))?.lExpression(); if (lexpression != null) { _declarationFinder.AddUnboundContext(_currentParent, lexpression, withExpression); } else { Logger.Warn( $"Default Context: Failed to resolve {expression.GetText()}. Binding as much as we can."); } } IParameterizedDeclaration defaultMember = null; if (boundExpression.ReferencedDeclaration != null && boundExpression.ReferencedDeclaration.DeclarationType != DeclarationType.Project && boundExpression.ReferencedDeclaration.AsTypeDeclaration != null) { var module = boundExpression.ReferencedDeclaration.AsTypeDeclaration; var members = _declarationFinder.Members(module); defaultMember = (IParameterizedDeclaration)members.FirstOrDefault(member => member is IParameterizedDeclaration && member.Attributes.HasDefaultMemberAttribute() && (isAssignmentTarget ? member.DeclarationType.HasFlag(DeclarationType.Procedure) : member.DeclarationType.HasFlag(DeclarationType.Function))); } _boundExpressionVisitor.AddIdentifierReferences( boundExpression, _qualifiedModuleName, _currentScope, _currentParent, isAssignmentTarget && (defaultMember == null || isSetAssignment || defaultMember.Parameters.All(param => param.IsOptional)), hasExplicitLetStatement, isSetAssignment); }
private void ResolveDefault( ParserRuleContext expression, StatementResolutionContext statementContext = StatementResolutionContext.Undefined, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false, bool isSetAssignment = false) { var withExpression = GetInnerMostWithExpression(); var boundExpression = _bindingService.ResolveDefault( _moduleDeclaration, _currentParent, expression, withExpression, statementContext); if (boundExpression.Classification == ExpressionClassification.ResolutionFailed) { var lexpression = expression as VBAParser.LExpressionContext ?? expression.GetChild <VBAParser.LExpressionContext>(0) ?? (expression as VBAParser.LExprContext ?? expression.GetChild <VBAParser.LExprContext>(0))?.lExpression(); if (lexpression != null) { _declarationFinder.AddUnboundContext(_currentParent, lexpression, withExpression); } else { Logger.Warn( $"Default Context: Failed to resolve {expression.GetText()}. Binding as much as we can."); } } var hasDefaultMember = false; if (boundExpression.ReferencedDeclaration != null && boundExpression.ReferencedDeclaration.DeclarationType != DeclarationType.Project && boundExpression.ReferencedDeclaration.AsTypeDeclaration != null) { var module = boundExpression.ReferencedDeclaration.AsTypeDeclaration; var members = _declarationFinder.Members(module); hasDefaultMember = members.Any(m => m.Attributes.Any(a => a.Name == $"{m.IdentifierName}.VB_UserMemId" && a.Values.SingleOrDefault() == "0")); } _boundExpressionVisitor.AddIdentifierReferences(boundExpression, _qualifiedModuleName, _currentScope, _currentParent, (!hasDefaultMember || isSetAssignment) && isAssignmentTarget, hasExplicitLetStatement); }