public IExpression MissingExpr() { IAddressOutExpression iaoe = Builder.AddrOutExpr(); iaoe.Expression = Builder.LiteralExpr(0); return(iaoe); }
protected override IExpression ConvertAddressOut(IAddressOutExpression iaoe) { iaoe = (IAddressOutExpression)base.ConvertAddressOut(iaoe); bool shouldDelete = false; AddReplicateStatement(iaoe.Expression, null, ref shouldDelete); return(iaoe); }
protected override IExpression ConvertAddressOut(IAddressOutExpression iaoe) { IVariableDeclaration targetVar = Recognizer.GetVariableDeclaration(iaoe.Expression); if (targetVar == null || variablesDefinedNonPointMass.Contains(targetVar)) { return(base.ConvertAddressOut(iaoe)); } IMethodInvokeExpression imie = context.FindAncestor <IMethodInvokeExpression>(); ProcessDefinition(imie, targetVar, isLhs: false); return(base.ConvertAddressOut(iaoe)); }
public override bool Equals(object obj) { if (this == obj) { return(true); } IAddressOutExpression expression = obj as IAddressOutExpression; if (expression == null) { return(false); } return(Expression.Equals(expression.Expression)); }
protected override IExpression ConvertMethodInvoke(IMethodInvokeExpression imie) { if (CodeRecognizer.IsInfer(imie)) { return(ConvertInfer(imie)); } foreach (IExpression arg in imie.Arguments) { if (arg is IAddressOutExpression) { IAddressOutExpression iaoe = (IAddressOutExpression)arg; targetsOfCurrentAssignment.Add(iaoe.Expression); } } if (Recognizer.IsStaticGenericMethod(imie, new Func <IList <PlaceHolder>, int[][], PlaceHolder[][]>(Factor.JaggedSubarray))) { IExpression arrayExpr = imie.Arguments[0]; IVariableDeclaration ivd = Recognizer.GetVariableDeclaration(imie.Arguments[0]); if (ivd != null && (arrayExpr is IVariableReferenceExpression) && this.variablesLackingVariableFactor.Contains(ivd) && !marginalOfVariable.ContainsKey(ivd)) { VariableInformation vi = VariableInformation.GetVariableInformation(context, ivd); IList <IStatement> stmts = Builder.StmtCollection(); CreateMarginalChannel(ivd, vi, stmts); Containers defContainers = context.InputAttributes.Get <Containers>(ivd); int ancIndex = defContainers.GetMatchingAncestorIndex(context); Containers missing = defContainers.GetContainersNotInContext(context, ancIndex); stmts = Containers.WrapWithContainers(stmts, missing.outputs); context.AddStatementsBeforeAncestorIndex(ancIndex, stmts); // none of the arguments should need to be transformed IExpression indicesExpr = imie.Arguments[1]; IExpression marginalExpr = Builder.VarRefExpr(marginalOfVariable[ivd]); IMethodInvokeExpression mie = Builder.StaticGenericMethod(new Models.FuncOut <IList <PlaceHolder>, int[][], IList <PlaceHolder>, PlaceHolder[][]>(Factor.JaggedSubarrayWithMarginal), new Type[] { Utilities.Util.GetElementType(arrayExpr.GetExpressionType()) }, arrayExpr, indicesExpr, marginalExpr); return(mie); } } return(base.ConvertMethodInvoke(imie)); }
public virtual void VisitAddressOutExpression(IAddressOutExpression value) { VisitExpression(value.Expression); }
protected override IExpression ConvertMethodInvoke(IMethodInvokeExpression imie) { if (Recognizer.IsStaticGenericMethod(imie, new Func <PlaceHolder, ICompilerAttribute, PlaceHolder>(Attrib.Var))) { IVariableReferenceExpression ivre = imie.Arguments[0] as IVariableReferenceExpression; IVariableDeclaration target = ivre.Variable.Resolve(); IExpression expr = CodeRecognizer.RemoveCast(imie.Arguments[1]); AddAttribute(target, expr); return(null); } else if (Recognizer.IsStaticMethod(imie, new Action <object, object>(Attrib.InitialiseTo))) { IVariableReferenceExpression ivre = CodeRecognizer.RemoveCast(imie.Arguments[0]) as IVariableReferenceExpression; IVariableDeclaration target = ivre.Variable.Resolve(); context.OutputAttributes.Set(target, new InitialiseTo(imie.Arguments[1])); return(null); } else if (CodeRecognizer.IsInfer(imie)) { inferCount++; object decl = Recognizer.GetDeclaration(imie.Arguments[0]); if (decl != null && !context.InputAttributes.Has <IsInferred>(decl)) { context.InputAttributes.Set(decl, new IsInferred()); } // the arguments must not be substituted for their values, so we don't call ConvertExpression List <IExpression> newArgs = new List <IExpression>(); foreach (var arg in imie.Arguments) { newArgs.Add(CodeRecognizer.RemoveCast(arg)); } IMethodInvokeExpression mie = Builder.MethodInvkExpr(); mie.Method = imie.Method; mie.Arguments.AddRange(newArgs); context.InputAttributes.CopyObjectAttributesTo(imie, context.OutputAttributes, mie); return(mie); } IExpression converted = base.ConvertMethodInvoke(imie); if (converted is IMethodInvokeExpression) { var mie = (IMethodInvokeExpression)converted; bool isAnd = Recognizer.IsStaticMethod(converted, new Func <bool, bool, bool>(Factors.Factor.And)); bool isOr = Recognizer.IsStaticMethod(converted, new Func <bool, bool, bool>(Factors.Factor.Or)); bool anyArgumentIsLiteral = mie.Arguments.Any(arg => arg is ILiteralExpression); if (anyArgumentIsLiteral) { if (isAnd) { if (mie.Arguments.Any(arg => arg is ILiteralExpression && ((ILiteralExpression)arg).Value.Equals(false))) { return(Builder.LiteralExpr(false)); } // any remaining literals must be true, and therefore can be ignored. var reducedArguments = mie.Arguments.Where(arg => !(arg is ILiteralExpression)); if (reducedArguments.Count() == 1) { return(reducedArguments.First()); } else { return(Builder.LiteralExpr(true)); } } else if (isOr) { if (mie.Arguments.Any(arg => arg is ILiteralExpression && ((ILiteralExpression)arg).Value.Equals(true))) { return(Builder.LiteralExpr(true)); } // any remaining literals must be false, and therefore can be ignored. var reducedArguments = mie.Arguments.Where(arg => !(arg is ILiteralExpression)); if (reducedArguments.Count() == 1) { return(reducedArguments.First()); } else { return(Builder.LiteralExpr(false)); } } else if (Recognizer.IsStaticMethod(converted, new Func <bool, bool>(Factors.Factor.Not))) { bool allArgumentsAreLiteral = mie.Arguments.All(arg => arg is ILiteralExpression); if (allArgumentsAreLiteral) { return(Builder.LiteralExpr(evaluator.Evaluate(mie))); } } } foreach (IExpression arg in mie.Arguments) { if (arg is IAddressOutExpression) { IAddressOutExpression iaoe = (IAddressOutExpression)arg; IVariableDeclaration ivd = Recognizer.GetVariableDeclaration(iaoe.Expression); if (ivd != null) { FactorManager.FactorInfo info = CodeRecognizer.GetFactorInfo(context, mie); if (info != null && info.IsDeterministicFactor && !context.InputAttributes.Has <DerivedVariable>(ivd)) { context.InputAttributes.Set(ivd, new DerivedVariable()); } } } } } return(converted); }
//=========================================================== // Expression 分岐 //=========================================================== public virtual void WriteExpression(IExpression expression) { if (expression == null) { return; } mwg.Reflector.CppCli.ExpressionWriter.WriteExpression(this, expression, false); #if FALSE #pragma warning disable 612 IMemberInitializerExpression expression3 = expression as IMemberInitializerExpression; if (expression3 != null) { this.WriteMemberInitializerExpression(expression3); return; } IAddressOutExpression expression27 = expression as IAddressOutExpression; if (expression27 != null) { this.WriteAddressOutExpression(expression27); return; } IAddressReferenceExpression expression26 = expression as IAddressReferenceExpression; if (expression26 != null) { this.WriteAddressReferenceExpression(expression26); return; } IDelegateCreateExpression iDelegateCreateExpression = expression as IDelegateCreateExpression; if (iDelegateCreateExpression != null) { this.WriteDelegateCreateExpression(iDelegateCreateExpression); return; } IMethodInvokeExpression iMethodInvokeExpression = expression as IMethodInvokeExpression; if (iMethodInvokeExpression != null) { this.WriteMethodInvokeExpression(iMethodInvokeExpression); return; } IVariableDeclarationExpression expression15 = expression as IVariableDeclarationExpression; if (expression15 != null) { this.WriteVariableDeclaration(expression15.Variable); return; } ITypeOfExpression iTypeOfExpression = expression as ITypeOfExpression; if (iTypeOfExpression != null) { this.WriteTypeOfExpression(iTypeOfExpression); return; } ISnippetExpression iSnippetExpression = expression as ISnippetExpression; if (iSnippetExpression != null) { this.WriteSnippetExpression(iSnippetExpression); return; } IUnaryExpression iUnaryExpression = expression as IUnaryExpression; if (iUnaryExpression != null) { this.WriteUnaryExpression(iUnaryExpression); return; } IObjectCreateExpression iObjectCreateExpression = expression as IObjectCreateExpression; if (iObjectCreateExpression != null) { this.WriteObjectCreateExpression(iObjectCreateExpression); return; } IVariableReferenceExpression iVariableReferenceExpression = expression as IVariableReferenceExpression; if (iVariableReferenceExpression != null) { this.WriteVariableReferenceExpression(iVariableReferenceExpression); return; } IThisReferenceExpression expression12 = expression as IThisReferenceExpression; if (expression12 != null) { this.WriteThisReferenceExpression(expression12); return; } ITryCastExpression iTryCastExpression = expression as ITryCastExpression; if (iTryCastExpression != null) { this.WriteTryCastExpression(iTryCastExpression); return; } IConditionExpression expression9 = expression as IConditionExpression; if (expression9 != null) { this.WriteConditionExpression(expression9); return; } IFieldReferenceExpression iFieldReferenceExpression = expression as IFieldReferenceExpression; if (iFieldReferenceExpression != null) { this.WriteFieldReferenceExpression(iFieldReferenceExpression); return; } IPropertyIndexerExpression iPropertyIndexerExpression = expression as IPropertyIndexerExpression; if (iPropertyIndexerExpression != null) { this.WritePropertyIndexerExpression(iPropertyIndexerExpression); return; } ITypeReferenceExpression iTypeReferenceExpression = expression as ITypeReferenceExpression; if (iTypeReferenceExpression != null) { this.WriteTypeReferenceExpression(iTypeReferenceExpression); return; } IMethodReferenceExpression iMethodReferenceExpression = expression as IMethodReferenceExpression; if (iMethodReferenceExpression != null) { this.WriteMethodReferenceExpression(iMethodReferenceExpression); return; } IPropertyReferenceExpression iPropertyReferenceExpression = expression as IPropertyReferenceExpression; if (iPropertyReferenceExpression != null) { this.WritePropertyReferenceExpression(iPropertyReferenceExpression); return; } ICastExpression expression5 = expression as ICastExpression; if (expression5 != null) { this.WriteCastExpression(expression5); return; } ICanCastExpression iCanCastExpression = expression as ICanCastExpression; if (iCanCastExpression != null) { this.WriteCanCastExpression(iCanCastExpression); return; } ICastExpression iCastExpression = expression as ICastExpression; if (iCastExpression != null) { this.WriteCastExpression(iCastExpression); return; } ILiteralExpression literalExpression = expression as ILiteralExpression; if (literalExpression != null) { this.WriteLiteralExpression(literalExpression); return; } IBinaryExpression iBinaryExpression = expression as IBinaryExpression; if (iBinaryExpression != null) { mwg.Reflector.CppCli.ExpressionWriter.WriteExpression(this, expression, true); //this.WriteBinaryExpression(iBinaryExpression); return; } IArrayIndexerExpression expression30 = expression as IArrayIndexerExpression; if (expression30 != null) { this.WriteArrayIndexerExpression(expression30); return; } IAddressDereferenceExpression expression29 = expression as IAddressDereferenceExpression; if (expression29 != null) { this.WriteAddressDereferenceExpression(expression29); return; } IAddressOfExpression expression28 = expression as IAddressOfExpression; if (expression28 != null) { this.WriteAddressOfExpression(expression28); return; } IArgumentListExpression expression25 = expression as IArgumentListExpression; if (expression25 != null) { this.WriteArgumentListExpression(expression25); return; } IBaseReferenceExpression iBaseReferenceExpression = expression as IBaseReferenceExpression; if (iBaseReferenceExpression != null) { this.WriteBaseReferenceExpression(iBaseReferenceExpression); return; } IArgumentReferenceExpression expression13 = expression as IArgumentReferenceExpression; if (expression13 != null) { this.WriteArgumentReferenceExpression(expression13); return; } IArrayCreateExpression expression10 = expression as IArrayCreateExpression; if (expression10 != null) { this.WriteArrayCreateExpression(expression10); return; } IAssignExpression iAssignExpression = expression as IAssignExpression; if (iAssignExpression != null) { this.WriteAssignExpression(iAssignExpression); return; } IBlockExpression expression2 = expression as IBlockExpression; if (expression2 != null) { this.WriteBlockExpression(expression2); return; } #pragma warning restore 612 this.Write(expression.ToString()); #endif }
protected override IExpression ConvertMethodInvoke(IMethodInvokeExpression imie) { if (imie.Arguments.Any(arg => arg is IAddressOutExpression)) { Set <IVariableDeclaration> oldVariablesInExpression = (Set <IVariableDeclaration>)variablesInExpression.Clone(); variablesInExpression.Clear(); ConvertExpression(imie.Method); foreach (var arg in imie.Arguments) { if (!(arg is IAddressOutExpression)) { ConvertExpression(arg); } } foreach (var arg in imie.Arguments) { if (arg is IAddressOutExpression) { IAddressOutExpression iaoe = (IAddressOutExpression)arg; IExpression target; var indices = Recognizer.GetIndices(iaoe.Expression, out target); if (target is IVariableReferenceExpression || target is IVariableDeclarationExpression) { IVariableDeclaration ivd = Recognizer.GetVariableDeclaration(target); HoistingInfo info = GetOrCreateHoistingInfo(ivd); int arrayDepth = info.maxDepthWhereDimensionCouldMatter.Length; for (int bracket = 0; bracket < indices.Count; bracket++) { for (int dim = 0; dim < indices[bracket].Count; dim++) { var index = indices[bracket][dim]; if (index is IVariableReferenceExpression) { IVariableDeclaration indexVar = Recognizer.GetVariableDeclaration(index); if (variablesInExpression.Contains(indexVar) || !unbrokenLoopVars.Contains(indexVar)) { // index is used on rhs or the loop is broken, so the dimension matters. SetDimensionMattersAtDepth(info, bracket, dim, arrayDepth); } } else { // index is not a loop counter, so the dimension matters. SetDimensionMattersAtDepth(info, bracket, dim, arrayDepth); } } } // all deeper dimensions matter for (int bracket = indices.Count; bracket < arrayDepth; bracket++) { for (int dim = 0; dim < info.maxDepthWhereDimensionCouldMatter[bracket].Length; dim++) { SetDimensionMattersAtDepth(info, bracket, dim, arrayDepth); } } } } } variablesInExpression.AddRange(oldVariablesInExpression); return(imie); } else { return(base.ConvertMethodInvoke(imie)); } }
private void WriteAddressOutExpression(IAddressOutExpression expression, IFormatter formatter) { formatter.Write("["); this.WriteExpression(expression.Expression, formatter); formatter.Write("]"); }
public override void VisitAddressOutExpression(IAddressOutExpression value) { WriteUnsupported(value); }
public virtual void VisitAddressOutExpression(IAddressOutExpression value) { this.VisitExpression(value.Expression); }
public virtual IExpression TransformAddressOutExpression(IAddressOutExpression value) { value.Expression = this.TransformExpression(value.Expression); return value; }