private IBoundExpression ResolveEnclosingProjectNamespace() { /* Namespace tier 3: * Enclosing Project namespace: The enclosing project itself, a referenced project, or a * procedural module contained in the enclosing project. */ if (_declarationFinder.IsMatch(_project.ProjectName, _name)) { return(new SimpleNameExpression(_project, ExpressionClassification.Project, _context)); } var referencedProject = _declarationFinder.FindReferencedProject(_project, _name); if (referencedProject != null) { return(new SimpleNameExpression(referencedProject, ExpressionClassification.Project, _context)); } if (_module.DeclarationType == DeclarationType.ProceduralModule && _declarationFinder.IsMatch(_module.IdentifierName, _name)) { return(new SimpleNameExpression(_module, ExpressionClassification.ProceduralModule, _context)); } var proceduralModuleEnclosingProject = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, _name, DeclarationType.ProceduralModule); if (proceduralModuleEnclosingProject != null) { return(new SimpleNameExpression(proceduralModuleEnclosingProject, ExpressionClassification.ProceduralModule, _context)); } var defaultInstanceVariableClass = _declarationFinder.FindDefaultInstanceVariableClassEnclosingProject(_project, _module, _name); if (defaultInstanceVariableClass != null) { return(new SimpleNameExpression(defaultInstanceVariableClass, ExpressionClassification.Type, _context)); } return(null); }
private IBoundExpression ResolveEnclosingProject(string name) { /* Namespace tier 2: * Enclosing Project namespace: The enclosing project itself, a referenced project, or a * procedural module or class module contained in the enclosing project. */ if (_declarationFinder.IsMatch(_project.ProjectName, name)) { // Ensure there is no ambiguous matches var ambiguousClassModule = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, name, DeclarationType.ClassModule); if (ambiguousClassModule != null) { // We have an indeterminate result; let's check if this is a part of member access first... if (_expression.Parent.GetType().Name != nameof(VBAParser.MemberAccessExprContext)) { // There is no qualifier -- this is normally a VBA compile error throw new InvalidOperationException($"There cannot be a unqualified reference where the name '{name}' is ambiguous."); } } return(new SimpleNameExpression(_project, ExpressionClassification.Project, _expression)); } var referencedProject = _declarationFinder.FindReferencedProject(_project, name); if (referencedProject != null) { return(new SimpleNameExpression(referencedProject, ExpressionClassification.Project, _expression)); } if (_module.DeclarationType == DeclarationType.ProceduralModule && _declarationFinder.IsMatch(_module.IdentifierName, name)) { return(new SimpleNameExpression(_module, ExpressionClassification.ProceduralModule, _expression)); } var proceduralModuleEnclosingProject = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, name, DeclarationType.ProceduralModule); if (proceduralModuleEnclosingProject != null) { return(new SimpleNameExpression(proceduralModuleEnclosingProject, ExpressionClassification.ProceduralModule, _expression)); } if (_module.DeclarationType == DeclarationType.ClassModule && _declarationFinder.IsMatch(_module.IdentifierName, name)) { return(new SimpleNameExpression(_module, ExpressionClassification.Type, _expression)); } var classEnclosingProject = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, name, DeclarationType.ClassModule); if (classEnclosingProject != null) { return(new SimpleNameExpression(classEnclosingProject, ExpressionClassification.Type, _expression)); } return(null); }
private IBoundExpression ResolveProject() { if (_declarationFinder.IsMatch(_project.ProjectName, _name)) { return(new MemberAccessExpression(_project, ExpressionClassification.Project, _context, _unrestrictedNameContext, _lExpression)); } var referencedProjectRightOfDot = _declarationFinder.FindReferencedProject(_project, _name); if (referencedProjectRightOfDot != null) { return(new MemberAccessExpression(referencedProjectRightOfDot, ExpressionClassification.Project, _context, _unrestrictedNameContext, _lExpression)); } return(null); }
private IBoundExpression ResolveProject(IBoundExpression lExpression, string name) { /* * <l-expression> refers to the enclosing project and <unrestricted-name> is either the name of * the enclosing project or a referenced project. In this case, the member access expression is * classified as a project and refers to the specified project. */ if (_declarationFinder.IsMatch(_project.ProjectName, name)) { return(new MemberAccessExpression(_project, ExpressionClassification.Project, _expression, _unrestrictedNameContext, lExpression)); } var referencedProjectRightOfDot = _declarationFinder.FindReferencedProject(_project, name); if (referencedProjectRightOfDot != null) { return(new MemberAccessExpression(referencedProjectRightOfDot, ExpressionClassification.Project, _expression, _unrestrictedNameContext, lExpression)); } return(null); }
private IBoundExpression ResolveEnclosingProject(string name) { /* Namespace tier 2: * Enclosing Project namespace: The enclosing project itself, a referenced project, or a * procedural module or class module contained in the enclosing project. */ if (_declarationFinder.IsMatch(_project.ProjectName, name)) { return(new SimpleNameExpression(_project, ExpressionClassification.Project, _expression)); } var referencedProject = _declarationFinder.FindReferencedProject(_project, name); if (referencedProject != null) { return(new SimpleNameExpression(referencedProject, ExpressionClassification.Project, _expression)); } if (_module.DeclarationType == DeclarationType.ProceduralModule && _declarationFinder.IsMatch(_module.IdentifierName, name)) { return(new SimpleNameExpression(_module, ExpressionClassification.ProceduralModule, _expression)); } var proceduralModuleEnclosingProject = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, name, DeclarationType.ProceduralModule); if (proceduralModuleEnclosingProject != null) { return(new SimpleNameExpression(proceduralModuleEnclosingProject, ExpressionClassification.ProceduralModule, _expression)); } if (_module.DeclarationType == DeclarationType.ClassModule && _declarationFinder.IsMatch(_module.IdentifierName, name)) { return(new SimpleNameExpression(_module, ExpressionClassification.Type, _expression)); } var classEnclosingProject = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, name, DeclarationType.ClassModule); if (classEnclosingProject != null) { return(new SimpleNameExpression(classEnclosingProject, ExpressionClassification.Type, _expression)); } return(null); }