public override string GetPhpScriptReferenceCode(StringCollection code) { if (this.Method == null) { DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. Method not found. ParameterID:{0}, ActionID:{1}, ClassId:{2}", this.ParameterID, ActionId, this.ClassId); } else { SubMethodInfoPointer smi = this.Method as SubMethodInfoPointer; if (smi == null) { MethodClass mc = this.Method as MethodClass; if (ActionId != 0 && mc != null && mc.ActionList != null) { IAction act = mc.ActionList.GetActionById(ActionId); if (act != null) { smi = act.ActionMethod as SubMethodInfoPointer; } } } if (smi == null) { DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. method [{0}][{1}] found by parameter [{2}] is not a SubMethodInfoPointer", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID); } else { if (this.ActionBranch == null) { MethodClass mc = this.Method as MethodClass; if (mc != null && mc.SubMethod != null && mc.SubMethod.Count > 0) { IMethod0 m0 = mc.SubMethod.Peek(); AB_SubMethodAction asa = m0 as AB_SubMethodAction; if (asa != null) { this.SetActionBranch(asa); } } } if (this.ActionBranch == null) { DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. parameter [{2}] for method [{0}][{1}] missing ActionBranch", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID); } else { SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; string target = smi.Owner.GetPhpScriptReferenceCode(code); return(string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", target, mi.GetIndexCodePHP(smi, this.ActionBranch.BranchId))); } } } return(CodeName); }
public override ActionBranchParameter GetActionBranchParameterByName(string parameterName) { if (_actionData != null) { SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer; List <ParameterClassSubMethod> ps = smi.GetParameters(this); if (ps != null && ps.Count > 0) { foreach (ParameterClassSubMethod p in ps) { if (string.CompareOrdinal(p.Name, parameterName) == 0) { return(p); } } } } return(null); }
public override CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue) { if (this.Method == null) { DesignUtil.WriteToOutputWindowAndLog("Method not found. ParameterID:{0}, ActionID:{1}, ClassId:{2}", this.ParameterID, ActionId, this.ClassId); } else { SubMethodInfoPointer smi = this.Method as SubMethodInfoPointer; if (smi == null) { DesignUtil.WriteToOutputWindowAndLog("method [{0}][{1}] found by parameter [{2}] is not a SubMethodInfoPointer", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID); } else { SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; CodeExpression[] ps = mi.GetIndexCodes(smi, method, MemberId); CodeExpression ce = new CodeArrayIndexerExpression(smi.Owner.GetReferenceCode(method, statements, forValue), ps); return(ce); } } return(null); }
private MethodInfoPointer createPointer(MultiPanes viewersHolder, XmlNode rootNode) { MethodInfoPointer mp; if (_val is SubMethodInfo) { mp = new SubMethodInfoPointer(); } else { mp = new MethodInfoPointer(); } mp.Owner = Owner; mp.MemberName = _val.Name; ParameterInfo[] pifs = null; IDynamicMethodParameters dmp = Owner.ObjectInstance as IDynamicMethodParameters; if (dmp != null) { pifs = dmp.GetDynamicMethodParameters(_val.Name, null); } if (pifs == null) { pifs = _val.GetParameters(); } if (pifs != null && pifs.Length > 0) { Type[] ts = new Type[pifs.Length]; for (int i = 0; i < ts.Length; i++) { ts[i] = pifs[i].ParameterType; } mp.ParameterTypes = ts; } mp.SetMethodInfo(_val); return(mp); }
public ParameterClassArrayIndex(SubMethodInfoPointer method) : base(method) { }
public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { bool bRet; if (_actionData == null) { _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId); } SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer; SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; if (mi == null) { return(false); } if (mi.IsForeach) { ParameterClassSubMethod p = mi.GetParameterType(0, smi, this); StringBuilder sb = new StringBuilder(); string s1 = smi.Owner.CodeName; IObjectPointer op = smi.Owner; sb.Append(s1); while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null) { if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0) { s1 = op.Owner.CodeName; sb.Insert(0, "->"); sb.Insert(0, s1); } op = op.Owner; } if (op is ILocalvariable || op.Owner is ILocalvariable) { } else { sb.Insert(0, "$this->"); } s1 = sb.ToString(); string indents = Indentation.GetIndent(); string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "\r\n{2}foreach ({0} as {1}) {{\r\n", s1, p.CodeName, indents); methodCode.Add(s0); // Method.SubMethod.Push(this); data.AddSubMethod(this); Indentation.IndentIncrease(); bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, methodCode, data); Indentation.IndentDecrease(); Method.SubMethod.Pop(); // methodCode.Add(indents); methodCode.Add("}\r\n"); } else { string indents = Indentation.GetIndent(); StringBuilder sb = new StringBuilder(); string s1 = smi.Owner.CodeName; IObjectPointer op = smi.Owner; sb.Append(s1); while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null) { if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0) { s1 = op.Owner.CodeName; sb.Insert(0, "->"); sb.Insert(0, s1); } op = op.Owner; } if (op is ILocalvariable) { } else { sb.Insert(0, "$this->"); } s1 = sb.ToString(); ParameterClassSubMethod p = mi.GetParameterType(1, smi, this); p.ParameterID = _actionData.ParameterValues[1].ParameterID; string v = p.CodeName; string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "\r\n{3}foreach ({0} as {1} => {2} ) {{\r\n", s1, mi.GetIndexCodePHP(smi, this.BranchId), v, indents); methodCode.Add(s0); Method.SubMethod.Push(this); data.AddSubMethod(this); // Indentation.IndentIncrease(); bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, methodCode, data); Method.SubMethod.Pop(); // Indentation.IndentDecrease(); methodCode.Add(indents); methodCode.Add("}\r\n"); } return(bRet); }
public override bool OnExportJavaScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { bool bRet; if (_actionData == null) { _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId); // (ActionSubMethod)compiler.ActionEventList.GetAction(_actId); } if (_actionData == null) { return(false); } SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer; SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; if (mi == null) { return(false); } if (mi.IsForeach) { ParameterClassSubMethod p = mi.GetParameterType(0, smi, this); StringBuilder sb = new StringBuilder(); string s1 = smi.Owner.CodeName; IObjectPointer op = smi.Owner; sb.Append(s1); while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null) { if (!s1.StartsWith(op.Owner.CodeName, StringComparison.Ordinal)) { s1 = op.Owner.CodeName; sb.Insert(0, "."); sb.Insert(0, s1); } op = op.Owner; } s1 = sb.ToString(); string indents = Indentation.GetIndent(); string a = string.Format(CultureInfo.InvariantCulture, "a{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture)); string idx = string.Format(CultureInfo.InvariantCulture, "i{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture)); string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{4}var {3} = {1};\r\n{4}if({3}) for(var {0}=0;{0}<{3}.length;{0}++) {{\r\n{4}var {2}={3}[{0}]; \r\n", idx, s1, p.CodeName, a, indents); methodCode.Add(s0); Method.SubMethod.Push(this); data.AddSubMethod(this); Indentation.IndentIncrease(); bRet = base.OnExportJavaScriptCode(previousAction, nextAction, jsCode, methodCode, data); Indentation.IndentDecrease(); Method.SubMethod.Pop(); // methodCode.Add(indents); methodCode.Add("}\r\n"); } else { string indents = Indentation.GetIndent(); methodCode.Add(indents); methodCode.Add("for(var "); methodCode.Add(mi.GetInitStatementJS(smi, jsCode, methodCode, data, this.BranchId)); methodCode.Add(mi.GetTestExpressionJS(smi, jsCode, methodCode, data, this.BranchId)); methodCode.Add(mi.GetIncrementalStatementJS(smi, jsCode, methodCode, data, this.BranchId)); methodCode.Add(") {\r\n"); Method.SubMethod.Push(this); data.AddSubMethod(this); Indentation.IndentIncrease(); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { methodCode.Add(Indentation.GetIndent()); methodCode.Add("var "); methodCode.Add(cil.LocalPointer.CodeName); methodCode.Add("="); methodCode.Add(ValueTypeUtil.GetDefaultJavaScriptValueByType(cil.LocalPointer.BaseClassType)); methodCode.Add(";\r\n"); } } } bRet = base.OnExportJavaScriptCode(previousAction, nextAction, jsCode, methodCode, data); Method.SubMethod.Pop(); // Indentation.IndentDecrease(); methodCode.Add(indents); methodCode.Add("}\r\n"); } return(bRet); }
public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { bool bRet; if (_actionData == null) { _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId); // (ActionSubMethod)compiler.ActionEventList.GetAction(_actId); } SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer; SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; if (mi.IsForeach) { ParameterClassSubMethod p = mi.GetParameterType(0, smi, this); StringBuilder sb = new StringBuilder(); string s1 = smi.Owner.CodeName; CustomMethodParameterPointer cmpp = smi.Owner.Owner as CustomMethodParameterPointer; if (cmpp == null) { IObjectPointer op = smi.Owner; sb.Append(s1); while (!(op is ILocalvariable) && op.Owner != null && !(op.Owner is MethodClass) && op.Owner.Owner != null) { if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0) { s1 = op.Owner.CodeName; sb.Insert(0, "."); sb.Insert(0, s1); } op = op.Owner; } s1 = sb.ToString(); } string itemTypeString = null; if (mi.ItemType.IsGenericParameter) { CollectionPointer cp = smi.Owner as CollectionPointer; if (cp != null) { CustomPropertyPointer cpp = cp.Owner as CustomPropertyPointer; if (cpp != null) { DataTypePointer dtp = cpp.GetConcreteType(mi.ItemType); if (dtp != null) { itemTypeString = dtp.TypeString; } } } } if (string.IsNullOrEmpty(itemTypeString)) { itemTypeString = VPLUtil.GetTypeCSharpName(mi.ItemType); } string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}foreach({1} {2} in {3}) {{", Indentation.GetIndent(), itemTypeString, p.CodeName, s1); CodeStatement cis0 = new CodeSnippetStatement(s0); statements.Add(cis0); // if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(statements); } } } // CodeStatementCollection sc = new CodeStatementCollection(); Method.SubMethod.Push(this); //smi); CompilerUtil.AddSubMethod(method, this); bRet = base.OnExportCode(previousAction, nextAction, compiler, method, sc); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, sc, bRet); statements.AddRange(sc); // statements.Add(new CodeSnippetStatement(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}}}", Indentation.GetIndent()))); } else { CodeIterationStatement cis = new CodeIterationStatement(); cis.TestExpression = mi.GetTestExpression(smi, compiler, this.Method, method, statements, this.BranchId); cis.InitStatement = mi.GetInitStatement(smi, compiler, this.Method, method, statements, this.BranchId); cis.IncrementStatement = mi.GetIncrementalStatement(smi, compiler, this.Method, method, statements, this.BranchId); // Method.SubMethod.Push(this); //smi); CompilerUtil.AddSubMethod(method, this); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(cis.Statements); } } } bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet); // // statements.Add(cis); } return(bRet); }