private void ResolveDefault( ParserRuleContext expression, bool requiresLetCoercion = false, 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, requiresLetCoercion, isAssignmentTarget); _failedResolutionVisitor.CollectUnresolved(boundExpression, _currentParent, withExpression); _boundExpressionVisitor.AddIdentifierReferences( boundExpression, _qualifiedModuleName, _currentScope, _currentParent, isAssignmentTarget, 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."); } } 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); }
public static DeclarationType GetSearchDeclarationType(StatementResolutionContext statementContext) { switch (statementContext) { case StatementResolutionContext.LetStatement: return(DeclarationType.PropertyLet); case StatementResolutionContext.SetStatement: return(DeclarationType.PropertySet); default: return(DeclarationType.PropertyGet); } }
private IExpressionBinding VisitTypeOf( Declaration module, Declaration parent, VBAParser.RelationalOpContext typeOfIsExpression, VBAParser.TypeofexprContext typeOfLeftPartExpression, ParserRuleContext typeExpression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic booleanExpression = typeOfLeftPartExpression.expression(); var booleanExpressionBinding = Visit(module, parent, booleanExpression, withBlockVariable, StatementResolutionContext.Undefined); var typeExpressionBinding = VisitType(module, parent, (dynamic)typeExpression, withBlockVariable, StatementResolutionContext.Undefined); return(new TypeOfIsDefaultBinding(typeOfIsExpression, booleanExpressionBinding, typeExpressionBinding)); }
public SimpleNameDefaultBinding( DeclarationFinder declarationFinder, Declaration project, Declaration module, Declaration parent, ParserRuleContext context, string name, StatementResolutionContext statementContext) { _declarationFinder = declarationFinder; _project = project; _module = module; _parent = parent; _context = context; _name = name; _propertySearchType = StatementContext.GetSearchDeclarationType(statementContext); }
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); }
public SimpleNameDefaultBinding( DeclarationFinder declarationFinder, Declaration project, Declaration module, Declaration parent, ParserRuleContext context, string name, StatementResolutionContext statementContext) { _declarationFinder = declarationFinder; _project = project; _module = module; _parent = parent; _context = context; // hack; SimpleNameContext.Identifier() excludes the square brackets _name = context.Start.Text == "[" && context.Stop.Text == "]" ? "[" + name + "]" : name; _propertySearchType = StatementContext.GetSearchDeclarationType(statementContext); }
public IExpressionBinding BuildTree( Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, bool requiresLetCoercion = false, bool isLetAssignment = false) { return(Visit( module, parent, expression, withBlockVariable, statementContext, requiresLetCoercion, isLetAssignment)); }
public MemberAccessDefaultBinding( DeclarationFinder declarationFinder, Declaration project, Declaration module, Declaration parent, ParserRuleContext expression, IBoundExpression lExpression, string name, StatementResolutionContext statementContext, ParserRuleContext unrestrictedNameContext) { _declarationFinder = declarationFinder; _project = project; _module = module; _parent = parent; _context = expression; _lExpression = lExpression; _name = name; _propertySearchType = StatementContext.GetSearchDeclarationType(statementContext); _unrestrictedNameContext = unrestrictedNameContext; }
public MemberAccessDefaultBinding( DeclarationFinder declarationFinder, Declaration project, Declaration module, Declaration parent, VBAParser.MemberAccessExprContext expression, IExpressionBinding lExpressionBinding, StatementResolutionContext statementContext, ParserRuleContext unrestrictedNameContext) : this( declarationFinder, project, module, parent, expression, null, Identifier.GetName(expression.unrestrictedIdentifier()), statementContext, unrestrictedNameContext) { _lExpressionBinding = lExpressionBinding; }
private void ResolveDefault( ParserRuleContext expression, StatementResolutionContext statementContext = StatementResolutionContext.Undefined, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false) { var boundExpression = _bindingService.ResolveDefault( _moduleDeclaration, _currentParent, expression, GetInnerMostWithExpression(), statementContext); if (boundExpression.Classification == ExpressionClassification.ResolutionFailed) { Logger.Warn( string.Format( "Default Context: Failed to resolve {0}. Binding as much as we can.", expression.GetText())); } _boundExpressionVisitor.AddIdentifierReferences(boundExpression, _qualifiedModuleName, _currentScope, _currentParent, isAssignmentTarget, hasExplicitLetStatement); }
public MemberAccessDefaultBinding( DeclarationFinder declarationFinder, Declaration project, Declaration module, Declaration parent, VBAParser.ObjectPrintExprContext expression, IExpressionBinding lExpressionBinding, StatementResolutionContext statementContext, ParserRuleContext unrestrictedNameContext) : this( declarationFinder, project, module, parent, expression, null, Tokens.Print, statementContext, unrestrictedNameContext) { _lExpressionBinding = lExpressionBinding; }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.ParenthesizedExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic expressionParens = expression.expression(); var expressionBinding = Visit(module, parent, expressionParens, withBlockVariable, StatementResolutionContext.Undefined); return(new ParenthesizedDefaultBinding(expression, expressionBinding)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.NewExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { var typeExpressionBinding = VisitType(module, parent, expression.expression(), withBlockVariable, StatementResolutionContext.Undefined); if (typeExpressionBinding == null) { return(null); } return(new NewTypeBinding(_declarationFinder, module, parent, expression, typeExpressionBinding)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.AddressOfExpressionContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { return(_procedurePointerBindingContext.BuildTree(module, parent, expression, withBlockVariable, statementContext)); }
private IExpressionBinding VisitUnaryOp(Declaration module, Declaration parent, ParserRuleContext context, ParserRuleContext expr, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic exprExpr = expr; var exprBinding = Visit(module, parent, exprExpr, withBlockVariable, StatementResolutionContext.Undefined); return(new UnaryOpDefaultBinding(context, exprBinding)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.LExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic lexpr = expression.lExpression(); return(Visit(module, parent, lexpr, withBlockVariable, statementContext)); }
private IExpressionBinding VisitBinaryOp(Declaration module, Declaration parent, ParserRuleContext context, ParserRuleContext left, ParserRuleContext right, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic leftExpr = left; var leftBinding = Visit(module, parent, leftExpr, withBlockVariable, StatementResolutionContext.Undefined); dynamic rightExpr = right; var rightBinding = Visit(module, parent, rightExpr, withBlockVariable, StatementResolutionContext.Undefined); return(new BinaryOpDefaultBinding(context, leftBinding, rightBinding)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.CallStmtContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { // Call statements always have an argument list. // One of the reasons we're doing this is that an empty argument list could represent a call to a default member, // which requires us to use an IndexDefaultBinding. if (expression.CALL() == null) { dynamic lexpr = expression.expression(); var lexprBinding = Visit(module, parent, lexpr, withBlockVariable, StatementResolutionContext.Undefined); var argList = VisitArgumentList(module, parent, expression.argumentList(), withBlockVariable, StatementResolutionContext.Undefined); SetLeftMatch(lexprBinding, argList.Arguments.Count); return(new IndexDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression.expression(), lexprBinding, argList)); } else { var lexprBinding = Visit(module, parent, (dynamic)expression.expression(), withBlockVariable, StatementResolutionContext.Undefined); if (!(lexprBinding is IndexDefaultBinding)) { return(new IndexDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression.expression(), lexprBinding, new ArgumentList())); } else { return(lexprBinding); } } }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.IntegerExpressionContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { return(Visit(module, parent, (dynamic)expression.expression(), withBlockVariable, StatementResolutionContext.Undefined)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.LiteralExpressionContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { return(new LiteralDefaultBinding(expression)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.DictionaryAccessExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic lExpression = expression.lExpression(); var lExpressionBinding = Visit(module, parent, lExpression, withBlockVariable, StatementResolutionContext.Undefined); return(VisitDictionaryAccessExpression(module, parent, expression, expression.unrestrictedIdentifier(), lExpressionBinding, StatementResolutionContext.Undefined)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.LogicalNotOpContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { return(VisitUnaryOp(module, parent, expression, expression.expression(), withBlockVariable, StatementResolutionContext.Undefined)); }
public IExpressionBinding BuildTree(Declaration module, Declaration parent, ParserRuleContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { dynamic dynamicExpression = expression; var type = expression.GetType(); return(Visit(module, parent, dynamicExpression, withBlockVariable, statementContext)); }
private IExpressionBinding VisitDictionaryAccessExpression(Declaration module, Declaration parent, ParserRuleContext expression, ParserRuleContext nameContext, IBoundExpression lExpression, StatementResolutionContext statementContext) { /* * A dictionary access expression is syntactically translated into an index expression with the same * expression for <l-expression> and an argument list with a single positional argument with a * declared type of String and a value equal to the name value of <unrestricted-name>. */ var fakeArgList = new ArgumentList(); fakeArgList.AddArgument(new ArgumentListArgument(new LiteralDefaultBinding(nameContext), ArgumentListArgumentType.Positional)); return(new IndexDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, lExpression, fakeArgList)); }
public IBoundExpression Resolve(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, bool requiresLetCoercion = false, bool isLetAssignment = false) { IExpressionBinding bindingTree = BuildTree(module, parent, expression, withBlockVariable, statementContext); return(bindingTree?.Resolve()); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.WithDictionaryAccessExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { /* * A <with-member-access-expression> or <with-dictionary-access-expression> is * statically resolved as a normal member access or dictionary access expression, respectively, as if * the innermost enclosing With block variable was specified for <l-expression>. If there is no * enclosing With block, the <with-expression> is invalid. */ return(VisitDictionaryAccessExpression(module, parent, expression, expression.unrestrictedIdentifier(), withBlockVariable, StatementResolutionContext.Undefined)); }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.WithMemberAccessExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { return(new MemberAccessDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, withBlockVariable, expression.unrestrictedIdentifier().GetText(), statementContext, expression.unrestrictedIdentifier())); }
public IExpressionBinding BuildTree(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, bool requiresLetCoercion = false, bool isLetAssignment = false) { switch (expression) { case VBAParser.LExprContext lExprContext: return(Visit(module, parent, lExprContext.lExpression())); case VBAParser.CtLExprContext ctLExprContext: return(Visit(module, parent, ctLExprContext.lExpression())); case VBAParser.BuiltInTypeExprContext builtInTypeExprContext: return(Visit(builtInTypeExprContext.builtInType())); default: throw new NotSupportedException($"Unexpected context type {expression.GetType()}"); } }
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.RelationalOpContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext) { // To make the grammar we treat a type-of-is expression as a construct of the form "TYPEOF expression", where expression // is always "expression IS expression". if (expression.expression()[0] is VBAParser.TypeofexprContext) { return(VisitTypeOf(module, parent, expression, (VBAParser.TypeofexprContext)expression.expression()[0], expression.expression()[1], withBlockVariable, StatementResolutionContext.Undefined)); } return(VisitBinaryOp(module, parent, expression, expression.expression()[0], expression.expression()[1], withBlockVariable, StatementResolutionContext.Undefined)); }