public override void PropagateChanges(MethodInvocationExpression eval, List chain) { ExpressionCollection expressions = new ExpressionCollection(); foreach (object local1 in chain.Reversed) { if (!(local1 is ProcessAssignmentsToSpecialMembers.ChainItem)) { } ProcessAssignmentsToSpecialMembers.ChainItem item = (ProcessAssignmentsToSpecialMembers.ChainItem) RuntimeServices.Coerce(local1, typeof(ProcessAssignmentsToSpecialMembers.ChainItem)); if (item.Container is MethodInvocationExpression) { break; } if (item.Container is SlicingExpression) { SlicingExpression expression = item.Container; Expression[] expressionArray1 = new Expression[] { expression.get_Target().CloneNode(), expression.get_Indices().get_Item(0).get_Begin().CloneNode(), this.get_CodeBuilder().CreateReference(item.Local) }; expressions.Add(this.CreateConstructorInvocation(this._sliceValueTypeChangeConstructor, expressionArray1)); break; } MemberReferenceExpression container = item.Container; Expression[] args = new Expression[] { container.get_Target().CloneNode(), this.get_CodeBuilder().CreateStringLiteral(container.get_Name()), this.get_CodeBuilder().CreateReference(item.Local) }; expressions.Add(this.CreateConstructorInvocation(this._valueTypeChangeConstructor, args)); } MethodInvocationExpression expression3 = this.get_CodeBuilder().CreateMethodInvocation(this._propagateChanges); IArrayType type = this._valueTypeChangeType.MakeArrayType(1); expression3.get_Arguments().Add(this.get_CodeBuilder().CreateArray(type, expressions)); eval.get_Arguments().Add(expression3); }
public override void LeaveMethodInvocationExpression(Boo.Lang.Compiler.Ast.MethodInvocationExpression node) { ICallableType callable = node.Target.ExpressionType as ICallableType; if (callable != null) { CallableSignature signature = callable.GetSignature(); if (!signature.AcceptVarArgs) { return; } ExpandInvocation(node, signature.Parameters); return; } IMethod method = TypeSystemServices.GetOptionalEntity(node.Target) as IMethod; if (null == method || !method.AcceptVarArgs) { return; } ExpandInvocation(node, method.GetParameters()); }
override protected void ProcessBuiltinInvocation(MethodInvocationExpression node, BuiltinFunction function) { if (TypeSystemServices.IsQuackBuiltin(function)) BindDuck(node); else base.ProcessBuiltinInvocation(node, function); }
/// <summary> /// This turn a call to TryGetParemeter('item') where item is a local variable /// into a WrapIfNull(item) method call. /// </summary> /// <param name="node">The node.</param> public override void OnMethodInvocationExpression(MethodInvocationExpression node) { var expression = node.Target as ReferenceExpression; if (expression == null || expression.Name != "TryGetParameter") { base.OnMethodInvocationExpression(node); return; } var name = ((StringLiteralExpression)node.Arguments[0]).Value; var entity = NameResolutionService.Resolve(name); if (entity == null) { base.OnMethodInvocationExpression(node); return; } var parentNode = node.ParentNode; var mie = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateSelfReference(_currentMethod.DeclaringType), wrapNullValue); var item = new ReferenceExpression(node.LexicalInfo, name); TypeSystemServices.Bind(item, entity); mie.Arguments.Add(item); parentNode.Replace(node, mie); }
public object VisitInvocationExpression(InvocationExpression ie, object data) { B.Expression e = ConvertExpression(ie.TargetObject); if (e == null) { return(null); } if (settings.IsVisualBasic && ie.TargetObject is IdentifierExpression && currentStatement != null) { VariableResolver resolver = new VariableResolver(nameComparer); TypeReference typeRef = resolver.FindType((ie.TargetObject as IdentifierExpression).Identifier, currentStatement); if (typeRef != null && typeRef.IsArrayType) { // Visual Basic: indexer expression B.SlicingExpression s = new B.SlicingExpression(GetLexicalInfo(ie)); s.Target = e; foreach (Expression expr in ie.Arguments) { s.Indices.Add(new B.Slice(ConvertExpression(expr))); } return(s); } } B.MethodInvocationExpression r = new B.MethodInvocationExpression(GetLexicalInfo(ie), e); foreach (Expression expr in ie.Arguments) { e = ConvertExpression(expr); if (e != null) { r.Arguments.Add(e); } } return(r); }
public override void LeaveMethodInvocationExpression(Boo.Lang.Compiler.Ast.MethodInvocationExpression node) { ICallableType callable = node.Target.ExpressionType as ICallableType; if (callable == null) { return; } CallableSignature signature = callable.GetSignature(); if (!signature.AcceptVarArgs) { return; } if (node.Arguments.Count > 0 && AstUtil.IsExplodeExpression(node.Arguments[-1])) { // explode the arguments node.Arguments.ReplaceAt(-1, ((UnaryExpression)node.Arguments[-1]).Operand); return; } IParameter[] parameters = signature.Parameters; int lenMinusOne = parameters.Length - 1; IType varArgType = parameters[lenMinusOne].Type; ExpressionCollection varArgs = node.Arguments.PopRange(lenMinusOne); node.Arguments.Add(CodeBuilder.CreateArray(varArgType, varArgs)); }
public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { if (!arrayCreateExpression.ArrayInitializer.IsNull) { B.ArrayLiteralExpression ale = ConvertArrayLiteralExpression(arrayCreateExpression.ArrayInitializer); if (!arrayCreateExpression.IsImplicitlyTyped) { ale.Type = (B.ArrayTypeReference)ConvertTypeReference(arrayCreateExpression.CreateType); } return(ale); } string builtInName = (arrayCreateExpression.Arguments.Count > 1) ? "matrix" : "array"; B.MethodInvocationExpression mie = new B.MethodInvocationExpression(GetLexicalInfo(arrayCreateExpression), MakeReferenceExpression(builtInName)); TypeReference elementType = arrayCreateExpression.CreateType.Clone(); int[] newRank = new int[elementType.RankSpecifier.Length - 1]; for (int i = 0; i < newRank.Length; i++) { newRank[i] = elementType.RankSpecifier[i + 1]; } elementType.RankSpecifier = newRank; mie.Arguments.Add(MakeReferenceExpression(elementType)); ConvertExpressions(arrayCreateExpression.Arguments, mie.Arguments); return(mie); }
public object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { B.MethodInvocationExpression mie = new B.MethodInvocationExpression(GetLexicalInfo(raiseEventStatement)); mie.Target = new B.ReferenceExpression(raiseEventStatement.EventName); ConvertExpressions(raiseEventStatement.Arguments, mie.Arguments); return(new B.ExpressionStatement(mie)); }
protected override Statement ExpandImpl(MacroStatement macro){ if (macro.Arguments.Count == 0){ Context.Errors.Add(new CompilerError(macro.LexicalInfo, "sub macro requires at least one reference or string attribute for subview name")); } var call = new MethodInvocationExpression(AstUtil.CreateReferenceExpression("OutputSubView")); int i = 0; foreach (Expression argument in macro.Arguments){ i++; Expression exp = argument; if (i == 1){ //action and contrller parameters if (argument is ReferenceExpression && !(argument is MemberReferenceExpression)){ if (argument.ToCodeString().StartsWith("@") || argument.ToCodeString().Contains(".")){ exp = AstUtil.CreateReferenceExpression(argument.ToCodeString().Substring(1)); } else{ exp = new StringLiteralExpression(argument.ToCodeString()); } } } call.Arguments.Add(exp); } return new ExpressionStatement(call); }
public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { B.Constructor m = new B.Constructor(GetLexicalInfo(constructorDeclaration)); m.Modifiers = ConvertModifier(constructorDeclaration, B.TypeMemberModifiers.Private); ConvertAttributes(constructorDeclaration.Attributes, m.Attributes); if (currentType != null) { currentType.Members.Add(m); } ConvertParameters(constructorDeclaration.Parameters, m.Parameters); m.EndSourceLocation = GetEndLocation((INode)constructorDeclaration.Body ?? constructorDeclaration); m.Body = ConvertMethodBlock(constructorDeclaration.Body); ConstructorInitializer ci = constructorDeclaration.ConstructorInitializer; if (ci != null && !ci.IsNull) { B.Expression initializerBase; if (ci.ConstructorInitializerType == ConstructorInitializerType.Base) { initializerBase = new B.SuperLiteralExpression(); } else { initializerBase = new B.SelfLiteralExpression(); } B.MethodInvocationExpression initializer = new B.MethodInvocationExpression(initializerBase); ConvertExpressions(ci.Arguments, initializer.Arguments); m.Body.Insert(0, new B.ExpressionStatement(initializer)); } return(m); }
public override void LeaveMethodInvocationExpression(MethodInvocationExpression node) { if (LookingFor(node)) { Found(node); } }
public object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { module = new B.Module(); module.LexicalInfo = new B.LexicalInfo(fileName, 1, 1); compilationUnit.AcceptChildren(this, data); if (entryPointMethod != null) { bool allMembersAreStatic = true; foreach (B.TypeMember member in entryPointMethod.DeclaringType.Members) { allMembersAreStatic &= member.IsStatic; } if (allMembersAreStatic) { entryPointMethod.DeclaringType.Attributes.Add(MakeAttribute(("module"))); } else { lastLexicalInfo = entryPointMethod.LexicalInfo; B.Expression expr = MakeReferenceExpression(entryPointMethod.DeclaringType.Name + ".Main"); B.MethodInvocationExpression mie = new B.MethodInvocationExpression(lastLexicalInfo, expr); if (entryPointMethod.Parameters.Count > 0) { mie.Arguments.Add(MakeReferenceExpression("argv")); } B.SimpleTypeReference ret = entryPointMethod.ReturnType as B.SimpleTypeReference; if (ret.Name == "void" || ret.Name == "System.Void") module.Globals.Add(new B.ExpressionStatement(mie)); else module.Globals.Add(new B.ReturnStatement(lastLexicalInfo, mie, null)); } } B.Module tmp = module; module = null; return tmp; }
void NormalizeMethodInvocationTarget(MethodInvocationExpression node) { if (node.Target.NodeType != NodeType.ReferenceExpression) return; node.Target = MemberReferenceFromReference( (ReferenceExpression)node.Target, CallableResolutionService.ValidCandidates[0].Method); }
public static MethodInvocationExpression CreateMethodInvocationExpression(LexicalInfo li, Expression target, Expression arg) { MethodInvocationExpression mie = new MethodInvocationExpression(li); mie.Target = (Expression)target.Clone(); mie.Arguments.Add((Expression)arg.Clone()); mie.IsSynthetic = true; return mie; }
public ReturnValueVisitor() { normalizer = new NormalizeStatementModifiers(); mie = new MethodInvocationExpression { Target = AstUtil.CreateReferenceExpression("transform") }; }
public override void OnMethodInvocationExpression(MethodInvocationExpression node) { if (node is MethodInvocationExpression && node.Target is GenericReferenceExpression) { var genericReferenceExpression = (GenericReferenceExpression)node.Target; if (genericReferenceExpression.Target is MemberReferenceExpression) { var memberReferenceExpression = (MemberReferenceExpression)genericReferenceExpression.Target; if (memberReferenceExpression.Target is MemberReferenceExpression) { var memberReferenceExpression2 = (MemberReferenceExpression)memberReferenceExpression.Target; if (memberReferenceExpression2.Target is MemberReferenceExpression) { var memberReferenceExpression3 = (MemberReferenceExpression)memberReferenceExpression2.Target; if (memberReferenceExpression3.Target is ReferenceExpression) { var referenceExpression = (ReferenceExpression)memberReferenceExpression3.Target; if (referenceExpression.Name == "Boo" && memberReferenceExpression3.Name == "Lang" && memberReferenceExpression2.Name == "Builtins" && memberReferenceExpression.Name == "array" && 1 == ((ICollection)genericReferenceExpression.GenericArguments).Count) { TypeReference node2 = genericReferenceExpression.GenericArguments[0]; if (1 == ((ICollection)node.Arguments).Count && node.Arguments[0] is CastExpression) { var castExpression = (CastExpression)node.Arguments[0]; Expression target = castExpression.Target; if (castExpression.Type is SimpleTypeReference) { var simpleTypeReference = (SimpleTypeReference)castExpression.Type; if (simpleTypeReference.Name == "int") { var methodInvocationExpression = new MethodInvocationExpression(LexicalInfo.Empty); var arg_255_0 = methodInvocationExpression; var genericReferenceExpression2 = new GenericReferenceExpression(LexicalInfo.Empty); GenericReferenceExpression arg_226_0 = genericReferenceExpression2; var referenceExpression2 = new ReferenceExpression(LexicalInfo.Empty); string text = referenceExpression2.Name = "array"; Expression expression = arg_226_0.Target = referenceExpression2; TypeReferenceCollection typeReferenceCollection = genericReferenceExpression2.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[] { TypeReference.Lift(node2) }); Expression expression2 = arg_255_0.Target = genericReferenceExpression2; ExpressionCollection expressionCollection = methodInvocationExpression.Arguments = ExpressionCollection.FromArray(new Expression[] { Expression.Lift(target) }); ReplaceCurrentNode(methodInvocationExpression); } } } } } } } } } }
public override void OnMethodInvocationExpression(MethodInvocationExpression node) { base.OnMethodInvocationExpression(node); if (this.IsConstructorInvocation(node)) { base.EnsureDocumentInitialized(node); node.set_LexicalInfo(BooExtensions.AsLexicalInfo(base.doc.FindPrevious(node.get_LexicalInfo(), 'n'), node.get_LexicalInfo().get_FileName())); } }
public static Expression build_with(ReferenceExpression builder, MethodInvocationExpression build, ReferenceExpression frameWorkVersion) { var targetName = builder.Name; return new MethodInvocationExpression( new ReferenceExpression(targetName), build.Arguments[0], new StringLiteralExpression(frameWorkVersion.Name) ); }
private static string GetInvokedMethodName_SafeForPropertyEvals(MethodInvocationExpression mie) { if (mie.Target.ToString() == "__eval__") { BinaryExpression binaryExpression = (BinaryExpression)mie.Arguments[0]; MethodInvocationExpression right = (MethodInvocationExpression)binaryExpression.Right; return right.Target.ToString(); } return mie.Target.ToString(); }
public override void OnMethodInvocationExpression(MethodInvocationExpression node) { if (isWrite(node)) { while(isWrite(node.Arguments[0])) { node.Arguments[0] = get_arg(node.Arguments[0]); } } base.OnMethodInvocationExpression(node); }
private MethodInvocationExpression MethodInvocationForEventSubscription(BinaryExpression node, IMethod method) { var methodTarget = CodeBuilder.CreateMemberReference(node.Left.LexicalInfo, ((MemberReferenceExpression)node.Left).Target, method); var mie = new MethodInvocationExpression(methodTarget); mie.Arguments.Add(node.Right); BindExpressionType(mie, method.ReturnType); return mie; }
protected override Statement ExpandImpl(MacroStatement macro){ var call = new MethodInvocationExpression( new ReferenceExpression("__Export") ); call.Arguments.Add(new StringLiteralExpression(macro.Arguments[0].ToCodeString())); if(macro.Arguments.Count==2){ call.Arguments.Add(macro.Arguments[1]); } return new ExpressionStatement(call); }
public override void OnMethodInvocationExpression(MethodInvocationExpression node) { if (isWrite(node)) { var arg = get_arg(node); if(arg is ExpressionInterpolationExpression) { arg = joinInterpolations((ExpressionInterpolationExpression) arg); set_arg(node, arg); } } base.OnMethodInvocationExpression(node); }
protected virtual void OnMethodInvocationExpression(ArrayLiteralExpression dependencies, MethodInvocationExpression expression) { foreach (var arg in expression.Arguments) { var binaryExpression = arg as BinaryExpression; if (binaryExpression == null || binaryExpression.Operator != BinaryOperatorType.ShiftRight) continue; AddDependency(dependencies, binaryExpression); } }
override public void OnMethodInvocationExpression(MethodInvocationExpression node) { var tern = ProcessTargets(node); if (tern != null) { Visit(node.Arguments); ReplaceCurrentNode(tern); return; } base.OnMethodInvocationExpression(node); }
public static bool IsNewBlock(MethodInvocationExpression method, out Block block) { block = null; if (method.Arguments.Count > 0 && method.Arguments[method.Arguments.Count - 1] is BlockExpression) { block = ((BlockExpression)method.Arguments[method.Arguments.Count - 1]).Body; } return block != null; }
public static bool IsPossibleStartCoroutineInvocationForm(MethodInvocationExpression node) { MethodInvocationExpression expression = node; if (expression is Node) { Node node2; MethodInvocationExpression expression1 = node2 = expression; if ((1 != 0) && ((node2.get_ParentNode() is ExpressionStatement) || (node2.get_ParentNode() is YieldStatement))) { } } return IsRhsOfAssignment(node); }
public override Statement Expand(MacroStatement macro) { if (macro.Arguments.Count == 0) throw new MonoRailException("Section must be called with a name"); MacroStatement component = GetParentComponent(macro); componentContextName = ComponentNaming.GetComponentContextName(component); componentVariableName = ComponentNaming.GetComponentNameFor(component); string sectionName = macro.Arguments[0].ToString(); Block block = new Block(); //if (!Component.SupportsSection(section.Name)) // throw new ViewComponentException( String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", section.Name, ComponentName)); MethodInvocationExpression supportsSection = new MethodInvocationExpression( AstUtil.CreateReferenceExpression(componentVariableName + ".SupportsSection"), new StringLiteralExpression(sectionName)); //create the new exception RaiseStatement raiseSectionNotSupportted = new RaiseStatement( new MethodInvocationExpression( AstUtil.CreateReferenceExpression(typeof(ViewComponentException).FullName), new StringLiteralExpression( String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", sectionName, component.Arguments[0].ToString()) ) )); Block trueBlock = new Block(); trueBlock.Add(raiseSectionNotSupportted); IfStatement ifSectionNotSupported = new IfStatement(new UnaryExpression(UnaryOperatorType.LogicalNot, supportsSection), trueBlock, null); block.Add(ifSectionNotSupported); //componentContext.RegisterSection(sectionName); MethodInvocationExpression mie = new MethodInvocationExpression( new MemberReferenceExpression(new ReferenceExpression(componentContextName), "RegisterSection"), new StringLiteralExpression(sectionName), CodeBuilderHelper.CreateCallableFromMacroBody(CodeBuilder, macro)); block.Add(mie); IDictionary sections = (IDictionary) component["sections"]; if (sections == null) { component["sections"] = sections = new Hashtable(); } sections.Add(sectionName, block); return null; }
override protected IEntity CantResolveAmbiguousMethodInvocation(MethodInvocationExpression node, IEntity[] entities) { if (!Ducky || CallableResolutionService.ValidCandidates.Count == 0) { return base.CantResolveAmbiguousMethodInvocation(node, entities); } // ok, we have valid method invocation matches, let's // let the runtime decide which method is the best // match NormalizeMethodInvocationTarget(node); BindQuack(node.Target); BindDuck(node); return null; }
protected virtual void ExpandInvocation(MethodInvocationExpression node, IParameter[] parameters) { if (AstUtil.InvocationEndsWithExplodeExpression(node)) { // explode the arguments node.Arguments.ReplaceAt(-1, ((UnaryExpression)node.Arguments[-1]).Operand); return; } var lastParameterIndex = parameters.Length-1; var varArgType = parameters[lastParameterIndex].Type; var varArgs = node.Arguments.PopRange(lastParameterIndex); node.Arguments.Add(CodeBuilder.CreateArray(varArgType, varArgs)); }
protected override Statement ExpandImpl(MacroStatement macro){ if (macro.Arguments.Count == 0) { Context.Errors.Add(new CompilerError(macro.LexicalInfo, "call macro requires at least one reference or string attribute for action name")); } var basis = new ReferenceExpression("Html"); var method = new MemberReferenceExpression(basis, "RenderAction"); var call = new MethodInvocationExpression(method); int i = 0; var result = new Block(); foreach (Expression argument in macro.Arguments){ i++; Expression exp = argument; if (!(exp is HashLiteralExpression)){ //action and contrller parameters if (!(exp is NullLiteralExpression)){ exp = new StringLiteralExpression(argument.ToCodeString()); } call.Arguments.Add(exp); } else{ string name = "__rd"; result.Add( new DeclarationStatement( new Declaration(name, null), new MethodInvocationExpression(AstUtil.CreateReferenceExpression("RouteValueDictionary")) ) ); var dict = argument as HashLiteralExpression; foreach (ExpressionPair item in dict.Items){ result.Add( new MethodInvocationExpression( AstUtil.CreateReferenceExpression(name + ".Add"), item.First, item.Second ) ); } if (i == 2){ call.Arguments.Add(new NullLiteralExpression()); } call.Arguments.Add(AstUtil.CreateReferenceExpression(name)); } } result.Add(call); return result; }
private void ExpandInvocation(MethodInvocationExpression node, IParameter[] parameters) { if (node.Arguments.Count > 0 && AstUtil.IsExplodeExpression(node.Arguments[-1])) { // explode the arguments node.Arguments.ReplaceAt(-1, ((UnaryExpression)node.Arguments[-1]).Operand); return; } int lenMinusOne = parameters.Length-1; IType varArgType = parameters[lenMinusOne].Type; ExpressionCollection varArgs = node.Arguments.PopRange(lenMinusOne); node.Arguments.Add(CodeBuilder.CreateArray(varArgType, varArgs)); }
public override void LeaveMethodInvocationExpression(MethodInvocationExpression node) { IMethodBase methodBase = node.Target.Entity as IMethodBase; if (methodBase != null && methodBase.AcceptVarArgs) { IParameter[] parameters = methodBase.GetParameters(); if (parameters.Length == ((ICollection)node.Arguments).Count) { IType expressionType = node.Arguments[-1].ExpressionType; if (expressionType == parameters[parameters.Length + -1].Type) { node.Arguments[-1] = new UnaryExpression(UnaryOperatorType.Explode, node.Arguments[-1]); } } } }
private Expression FixCondition(Expression condition) { if (IsTryGetParameterInvocation(condition) == false) return condition; string name = ((ReferenceExpression) condition).Name.Substring(1); condition = new MethodInvocationExpression( new MemberReferenceExpression(new SuperLiteralExpression(), "TryGetParameter"), new StringLiteralExpression(name) ); var isNull = new MemberReferenceExpression(condition, "_IsIgnoreNullReferencingNotNullObject_"); return isNull; }
private static Expression[] GetExpressionsFromBlock(Block block) { List<Expression> expressions = new List<Expression>(block.Statements.Count); foreach (Statement statement in block.Statements) { if (statement is ExpressionStatement) expressions.Add((statement as ExpressionStatement).Expression); else if (statement is MacroStatement) { MacroStatement macroStatement = statement as MacroStatement; if (macroStatement.Arguments.Count == 0 && macroStatement.Body.IsEmpty) { // Assume it is a reference expression ReferenceExpression refExp = new ReferenceExpression(macroStatement.LexicalInfo); refExp.Name = macroStatement.Name; expressions.Add(refExp); } else { // Assume it is a MethodInvocation MethodInvocationExpression mie = new MethodInvocationExpression(macroStatement.LexicalInfo); mie.Target = new ReferenceExpression(macroStatement.LexicalInfo, macroStatement.Name); mie.Arguments = macroStatement.Arguments; if (macroStatement.Body.IsEmpty == false) { // If the macro statement has a block, // transform it into a block expression and pass that as the last argument // to the method invocation. BlockExpression be = new BlockExpression(macroStatement.LexicalInfo); be.Body = macroStatement.Body.CloneNode(); mie.Arguments.Add(be); } expressions.Add(mie); } } else { throw new InvalidOperationException(string.Format("Can not transform block with {0} into argument.", statement.GetType())); } } return expressions.ToArray(); }
public override void OnBinaryExpression(BinaryExpression node) { if (node.Operator != BinaryOperatorType.Equality) return; if (IsTryGetParameterInvocation(node.Left) == false && IsTryGetParameterInvocation(node.Right) == false) return; var mie = new MethodInvocationExpression(); var expression = AstUtil.CreateReferenceExpression("Castle.MonoRail.Views.Brail.IgnoreNull.AreEqual"); mie.Target = expression; mie.Arguments.Add(node.Left); mie.Arguments.Add(node.Right); ReplaceCurrentNode(mie); }
public object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { TypeReference t = objectCreateExpression.CreateType; if (t.IsArrayType) { throw new ApplicationException("ObjectCreateExpression cannot be called with an ArrayType"); } // HACK: Tricking out event handlers if (t.Type.EndsWith("EventHandler") && objectCreateExpression.Parameters.Count == 1) { return(ConvertExpression((Expression)objectCreateExpression.Parameters[0])); } B.MethodInvocationExpression mie = new B.MethodInvocationExpression(GetLexicalInfo(objectCreateExpression), MakeReferenceExpression(t)); ConvertExpressions(objectCreateExpression.Parameters, mie.Arguments); return(mie); }
public object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { module = new B.Module(); module.LexicalInfo = new B.LexicalInfo(fileName, 1, 1); compilationUnit.AcceptChildren(this, data); if (entryPointMethod != null) { bool allMembersAreStatic = true; foreach (B.TypeMember member in entryPointMethod.DeclaringType.Members) { allMembersAreStatic &= member.IsStatic; } if (allMembersAreStatic) { entryPointMethod.DeclaringType.Attributes.Add(MakeAttribute(("module"))); } else { lastLexicalInfo = entryPointMethod.LexicalInfo; B.Expression expr = MakeReferenceExpression(entryPointMethod.DeclaringType.Name + ".Main"); B.MethodInvocationExpression mie = new B.MethodInvocationExpression(lastLexicalInfo, expr); if (entryPointMethod.Parameters.Count > 0) { mie.Arguments.Add(MakeReferenceExpression("argv")); } B.SimpleTypeReference ret = entryPointMethod.ReturnType as B.SimpleTypeReference; if (ret.Name == "void" || ret.Name == "System.Void") { module.Globals.Add(new B.ExpressionStatement(mie)); } else { module.Globals.Add(new B.ReturnStatement(lastLexicalInfo, mie, null)); } } } B.Module tmp = module; module = null; return(tmp); }
override public bool EnterMethodInvocationExpression(Boo.Lang.Compiler.Ast.MethodInvocationExpression node) { return(false); }
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 static bool InvocationEndsWithExplodeExpression(MethodInvocationExpression node) { return(EndsWithExplodeExpression(node.Arguments)); }
private void SpliceName(MethodInvocationExpression ctor, Expression nameExpression) { ctor.NamedArguments.Add(Pair("Name", LiftMemberName(nameExpression))); }