public IReturnType GetTypeOfExpression(AST.Expression expr, IClass callingClass) { AST.Node node = expr; AST.LexicalInfo lexInfo; do { if (node == null) { return(null); } lexInfo = node.LexicalInfo; node = node.ParentNode; } while (lexInfo == null || lexInfo.FileName == null); if (!Initialize(ParserService.GetParseInformation(lexInfo.FileName), lexInfo.Line, lexInfo.Column)) { return(null); } if (callingClass != null) { this.callingClass = callingClass; } ResolveVisitor visitor = new ResolveVisitor(this); visitor.Visit(expr); if (visitor.ResolveResult == null) { return(null); } else { return(visitor.ResolveResult.ResolvedType); } }
public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) { if (!Initialize(parseInfo, expressionResult.Region.BeginLine, expressionResult.Region.BeginColumn)) { return(null); } LoggingService.Debug("Resolve " + expressionResult.ToString()); if (expressionResult.Expression == "__GlobalNamespace") // used for "import" completion { return(new NamespaceResolveResult(callingClass, callingMember, "")); } ResolveResult rr = CtrlSpaceResolveHelper.GetResultFromDeclarationLine(callingClass, callingMember as IMethodOrProperty, this.caretLine, this.caretColumn, expressionResult); if (rr != null) { return(rr); } AST.Expression expr; try { expr = Boo.Lang.Parser.BooParser.ParseExpression("expression", expressionResult.Expression); } catch (Exception ex) { LoggingService.Debug("Boo expression parser: " + ex.Message); return(null); } if (expr == null) { return(null); } if (expr is AST.IntegerLiteralExpression) { return(new IntegerLiteralResolveResult(callingClass, callingMember, pc.SystemTypes.Int32)); } if (expressionResult.Context == ExpressionFinder.BooAttributeContext.Instance) { AST.MethodInvocationExpression mie = expr as AST.MethodInvocationExpression; if (mie != null) { expr = mie.Target; } string name = expr.ToCodeString(); SearchTypeResult searchTypeResult = pc.SearchType(new SearchTypeRequest(name, 0, callingClass, cu, caretLine, caretColumn)); IReturnType rt = searchTypeResult.Result; if (rt != null && rt.GetUnderlyingClass() != null) { return(new TypeResolveResult(callingClass, callingMember, rt)); } rt = pc.SearchType(new SearchTypeRequest(name + "Attribute", 0, callingClass, cu, caretLine, caretColumn)).Result; if (rt != null && rt.GetUnderlyingClass() != null) { return(new TypeResolveResult(callingClass, callingMember, rt)); } if (BooProject.BooCompilerPC != null) { IClass c = BooProject.BooCompilerPC.GetClass("Boo.Lang." + char.ToUpper(name[0]) + name.Substring(1) + "Attribute", 0); if (c != null) { return(new TypeResolveResult(callingClass, callingMember, c)); } } string namespaceName = searchTypeResult.NamespaceResult; if (namespaceName != null) { return(new NamespaceResolveResult(callingClass, callingMember, namespaceName)); } return(null); } else { if (expr.NodeType == AST.NodeType.ReferenceExpression) { // this could be a macro if (BooProject.BooCompilerPC != null) { string name = ((AST.ReferenceExpression)expr).Name; IClass c = BooProject.BooCompilerPC.GetClass("Boo.Lang." + char.ToUpper(name[0]) + name.Substring(1) + "Macro", 0); if (c != null) { return(new TypeResolveResult(callingClass, callingMember, c)); } } } } ResolveVisitor visitor = new ResolveVisitor(this); visitor.Visit(expr); ResolveResult result = visitor.ResolveResult; if (expressionResult.Context == ExpressionContext.Type && result is MixedResolveResult) { result = (result as MixedResolveResult).TypeResult; } return(result); }
public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) { if (!Initialize(parseInfo, expressionResult.Region.BeginLine, expressionResult.Region.BeginColumn)) return null; LoggingService.Debug("Resolve " + expressionResult.ToString()); if (expressionResult.Expression == "__GlobalNamespace") { // used for "import" completion return new NamespaceResolveResult(callingClass, callingMember, ""); } ResolveResult rr = CtrlSpaceResolveHelper.GetResultFromDeclarationLine(callingClass, callingMember as IMethodOrProperty, this.caretLine, this.caretColumn, expressionResult); if (rr != null) return rr; AST.Expression expr; try { expr = Boo.Lang.Parser.BooParser.ParseExpression("expression", expressionResult.Expression); } catch (Exception ex) { LoggingService.Debug("Boo expression parser: " + ex.Message); return null; } if (expr == null) return null; if (expr is AST.IntegerLiteralExpression) return new IntegerLiteralResolveResult(callingClass, callingMember, pc.SystemTypes.Int32); if (expressionResult.Context == ExpressionFinder.BooAttributeContext.Instance) { AST.MethodInvocationExpression mie = expr as AST.MethodInvocationExpression; if (mie != null) expr = mie.Target; string name = expr.ToCodeString(); SearchTypeResult searchTypeResult = pc.SearchType(new SearchTypeRequest(name, 0, callingClass, cu, caretLine, caretColumn)); IReturnType rt = searchTypeResult.Result; if (rt != null && rt.GetUnderlyingClass() != null) return new TypeResolveResult(callingClass, callingMember, rt); rt = pc.SearchType(new SearchTypeRequest(name + "Attribute", 0, callingClass, cu, caretLine, caretColumn)).Result; if (rt != null && rt.GetUnderlyingClass() != null) return new TypeResolveResult(callingClass, callingMember, rt); if (BooProject.BooCompilerPC != null) { IClass c = BooProject.BooCompilerPC.GetClass("Boo.Lang." + char.ToUpper(name[0]) + name.Substring(1) + "Attribute", 0); if (c != null) return new TypeResolveResult(callingClass, callingMember, c); } string namespaceName = searchTypeResult.NamespaceResult; if (namespaceName != null) { return new NamespaceResolveResult(callingClass, callingMember, namespaceName); } return null; } else { if (expr.NodeType == AST.NodeType.ReferenceExpression) { // this could be a macro if (BooProject.BooCompilerPC != null) { string name = ((AST.ReferenceExpression)expr).Name; IClass c = BooProject.BooCompilerPC.GetClass("Boo.Lang." + char.ToUpper(name[0]) + name.Substring(1) + "Macro", 0); if (c != null) return new TypeResolveResult(callingClass, callingMember, c); } } } ResolveVisitor visitor = new ResolveVisitor(this); visitor.Visit(expr); ResolveResult result = visitor.ResolveResult; if (expressionResult.Context == ExpressionContext.Type && result is MixedResolveResult) result = (result as MixedResolveResult).TypeResult; return result; }
public IReturnType GetTypeOfExpression(AST.Expression expr, IClass callingClass) { AST.Node node = expr; AST.LexicalInfo lexInfo; do { if (node == null) return null; lexInfo = node.LexicalInfo; node = node.ParentNode; } while (lexInfo == null || lexInfo.FileName == null); if (!Initialize(ParserService.GetParseInformation(lexInfo.FileName), lexInfo.Line, lexInfo.Column)) return null; if (callingClass != null) this.callingClass = callingClass; ResolveVisitor visitor = new ResolveVisitor(this); visitor.Visit(expr); if (visitor.ResolveResult == null) return null; else return visitor.ResolveResult.ResolvedType; }