public static JAssignmentExpression Assign(this JExpression me, JExpression exp2) { var node = new JAssignmentExpression { Left = me, Right = exp2 }; return(node); }
public static JNewAnonymousClassExpression NewAnonymousType(JExpression type) { var x = New(type); return(new JNewAnonymousClassExpression { Type = x.Type, Invocation = x.Invocation }); }
public static JJsonNameValue JsonNameValue(string name, JExpression value) { return(new JJsonNameValue { Name = new JJsonMember { Name = name }, Value = value }); }
/// <summary> /// MyFunction(prm1, prm2) -> MyFunction.call(context, prm1, prm2) /// </summary> /// <param name="node"></param> /// <param name="context"></param> /// <returns></returns> public static void ToCallWithContext(JInvocationExpression node, JExpression context) { node.Member = node.Member.Member("call"); if (node.Arguments == null) { node.Arguments = new List <JExpression>(); } node.Arguments.Insert(0, J.This()); }
public static JExpression NewArray(IType type, JExpression size, JExpression[] items) { if (items == null) { items = new JExpression[0]; } return(new JNewArrayExpression { Type = type.JAccess(), Size = size, Items = items.ToList() }); }
public static JStatement Statement(this JExpression exp) { if (exp != null && exp is JVariableDeclarationExpression) { return(((JVariableDeclarationExpression)exp).Statement());//new JsVariableDeclarationStatement { Declaration = }; } return(new JExpressionStatement { Expression = exp }); }
void YieldReturnInCurrentStep(JExpression item) { var result = J.Value(true); var stepIndex = Steps.Count - 1; AddToCurrentStep(J.This().Member("_current").Assign(item).Statement()); AddToCurrentStep(_state().Assign(J.Value(stepIndex + 1)).Statement()); AddToCurrentStep(J.Member("result").Assign(result).Statement()); AddToCurrentStep(J.Return(result)); }
public static JInvocationExpression InvokeWithContextIfNeeded(this JExpression me, JExpression context, params JExpression[] prms) { if (context == null) { return(me.Invoke(prms)); } var prms2 = prms.ToList(); prms2.Insert(0, context); return(me.Member("call").Invoke(prms2.ToArray())); }
public static JInvocationExpression Invoke(this JExpression me, params JExpression[] prms) { var x = new JInvocationExpression { Member = me, Arguments = prms == null ? null : prms.ToList() }; var me2 = me as JMemberExpression; if (me2 != null) { x.Method = me2.Member as IMethod; } return(x); }
JExpression CreateAnonymousJsDelegate(JExpression instanceContext, JExpression func) { if (instanceContext == null) { return(func); } return(new JInvocationExpression { Member = new JMemberExpression { Name = "$CreateAnonymousDelegate" }, Arguments = new List <JExpression> { instanceContext, func } }); }
JExpression CreateJsExtensionDelegate(JExpression prm1, JExpression func) { if (prm1 == null) { return(func); } return(new JInvocationExpression { Member = new JMemberExpression { Name = "$CreateExtensionDelegate" }, Arguments = new List <JExpression> { prm1, func } }); }
public static JSwitchStatement Case(this JSwitchStatement node, JExpression value, List <JStatement> statements) { if (node.Sections == null) { node.Sections = new List <JSwitchSection>(); } node.Sections.Add(new JSwitchSection { Labels = new List <JSwitchLabel> { new JSwitchLabel { Expression = value } }, Statements = statements }); return(node); }
public JNode VisitArrayCreateResolveResult(ArrayCreateResolveResult res) { JExpression[] items = null; JExpression size = null; if (res.InitializerElements.IsNotNullOrEmpty()) { items = VisitExpressions(res.InitializerElements).ToArray(); } else if (res.SizeArguments.IsNotNullOrEmpty()) { size = VisitExpression(res.SizeArguments.Single()); } return(J.NewArray(res.Type, size, items)); }
public virtual List <JEntityDeclaration> _VisitField(IField fld) { var init2 = GetCreateFieldInitializer(fld); JExpression initializer = null; if (init2 != null) { initializer = JsCodeImporter.VisitExpression(init2); } var fe2 = new JFieldDeclaration { FieldDefinition = fld, Initializer = initializer, Type = fld.Type.JAccess(), Name = JNaming.JName(fld) }; ImportModifiers(fld, fe2); return(new List <JEntityDeclaration> { fe2 }); }
private JExpression ParenthesizeIfNeeded(ResolveResult res, JExpression exp) { if (exp is JParenthesizedExpression) { return(exp); } var nodes = res.GetNodes(); if (nodes == null) { return(exp); } var cspe = nodes.OfType <ParenthesizedExpression>().FirstOrDefault(); if (cspe == null) { return(exp); } return(new JParenthesizedExpression { Expression = exp }); }
public static JPostUnaryExpression PlusPlus(this JExpression exp) { return(new JPostUnaryExpression { Left = exp, Operator = "++" }); }
public static JMemberExpression Member(this JExpression member, string name) { return(new JMemberExpression { Name = name, PreviousMember = member }); }
public JNode VisitMethodGroupResolveResult(MethodGroupResolveResult res) { var info = res.GetInfo(); IMethod me; if (info != null && info.Conversion != null && info.Conversion.Method != null) { me = info.Conversion.Method; } else //happens when invoking a method with overloads, and a parameter is dynamic { var list = res.Methods.ToList(); if (list.Count == 0) { throw new Exception("Method group not resolved to any method"); } else if (list.Count == 1) { me = list[0]; } else { me = list[0]; } //TODO: verify all methods has the same js name } var isExtensionMethodStyle = me.IsExtensionMethod && !(res.TargetResult is TypeResolveResult);//TODO: IsExtensionMethodStyle(new CsInvocationExpression { entity = me, expression = node }); JExpression firstPrm = null; if (isExtensionMethodStyle) { firstPrm = (JExpression)Visit(res.TargetResult); } var node2 = JNaming.JAccess(me); JExpression node3; JExpression instanceContext = null; if (me.IsStatic || res.TargetResult == null) //getting ThisResolveResult even on static methods, getting TargetResult=null when MethodGroupResolveResult when using delegates { node3 = node2; } else { instanceContext = VisitExpression(res.TargetResult); node3 = instanceContext.Member(node2); } if (info != null && (instanceContext != null || firstPrm != null)) { var conv = info.Conversion; if (info.ConversionTargetType != null && !UseNativeFunctions(info.ConversionTargetType))//delegate type { var parentMethod = info.Nodes.FirstOrDefault().GetCurrentMethod(); if (parentMethod == null || !JMeta.ForceDelegatesAsNativeFunctions(parentMethod)) { if (parentMethod == null) { Log.Warn(info.Nodes.FirstOrDefault(), "GetParentMethod() returned null"); } var func = (JExpression)node2; if (instanceContext != null) { node3 = CreateJsDelegate(instanceContext, func); } else if (firstPrm != null) { node3 = CreateJsExtensionDelegate(firstPrm, func); } } } } return(node3); }
public void VisitExpression(JExpression node) { }
public static JBinaryExpression InstanceOf(this JExpression exp, JExpression exp2) { return(new JBinaryExpression { Left = exp, Operator = "instanceof", Right = exp2 }); }
public static JMemberExpression Member(this JExpression member, JMemberExpression exp) { exp.PreviousMember = member; return(exp); }
public static JCastExpression Cast(JExpression exp, JMemberExpression type) { return(new JCastExpression { Expression = exp, Type = type }); }
public static JBinaryExpression NotEqual(this JExpression exp, JExpression exp2) { return(new JBinaryExpression { Left = exp, Operator = "!=", Right = exp2 }); }
public static JWhileStatement While(JExpression condition, JStatement statement = null) { return(new JWhileStatement { Condition = condition, Statement = statement }); }
public static JExpression Conditional(this JExpression condition, JExpression trueExp, JExpression falseExp) { return(new JConditionalExpression { Condition = condition, TrueExpression = trueExp, FalseExpression = falseExp }); }
public static JBinaryExpression BitwiseOr(this JExpression exp, JExpression exp2) { return(new JBinaryExpression { Left = exp, Operator = "|", Right = exp2 }); }
public static JParenthesizedExpression Parentheses(this JExpression exp) { return(new JParenthesizedExpression { Expression = exp }); }
public static JPostUnaryExpression MinusMinus(this JExpression exp) { return(new JPostUnaryExpression { Left = exp, Operator = "--" }); }
public static JBinaryExpression GreaterThan(this JExpression exp, JExpression exp2) { return(new JBinaryExpression { Left = exp, Operator = ">", Right = exp2 }); }
public static JBinaryExpression LessThanOrEqualTo(this JExpression exp, JExpression exp2) { return(new JBinaryExpression { Left = exp, Operator = "<=", Right = exp2 }); }