void GenenrateSubject(EmitExpContext context) { ILGenerator il = context.ILout; bool isgen = false; if ((ListExp is VarExp)) { VarExp varexp = ListExp as VarExp; if (ReflectionUtil.IsStruct(varexp.RetType)) { if (varexp.VarSymbol is SymbolVar) { il.Emit(OpCodes.Ldloca, (varexp.VarSymbol as SymbolVar).VarBuilder); isgen = true; } else if (varexp.VarSymbol is SymbolArg) { il.Emit(OpCodes.Ldarga, (varexp.VarSymbol as SymbolArg).ArgIndex); isgen = true; } } } if (!isgen) { ListExp.Generate(context); } }
public override bool Accepts(ListExp exp) { if (listItems == null) { // split the literal by whitespace. string[] tokens = StringTokenizer.Tokenize(literal); // Trace.WriteLine(string.Format("literal:'{0}' token size:{1}",literal,tokens.Length)); listItems = new StringToken[tokens.Length]; for (int i = 0; i < tokens.Length; i++) { listItems[i] = new StringToken(tokens[i], builder, context); } } Expression body = exp.exp; for (int i = 0; i < listItems.Length; i++) { body = Residual.Calc(body, listItems[i], builder); // Trace.WriteLine("list residual: "+ ExpPrinter.printContentModel(body)); if (body == Expression.NotAllowed) { return(false); } } return(body.IsNullable); }
void generateList(EmitStmtContext context) { ILGenerator il = context.ILout; EmitExpContext expContext = new EmitExpContext(context); ListExp.Generate(expContext); EmitHelper.StormVar(il, listSymbol.VarBuilder); }
public override string ToCode() { StringBuilder buf = new StringBuilder(); buf.Append(ListExp != null ? ListExp.ToCode() : ""); buf.Append("的"); buf.Append(MemberToken != null ? MemberToken.GetText() : ""); return(buf.ToString()); }
public Expression OnList(ListExp exp) { if (token.Accepts(exp)) { return(Expression.Empty); } else { return(Expression.NotAllowed); } }
public void QueryMap6() { int begin = 1; int end = 10; Statement stmt = new Statement(); stmt.SetNamespace(args.ns); stmt.SetSetName(setName); stmt.SetFilter(Filter.Range(binName, begin, end)); // Map bin contains keys "A" and "C". QueryPolicy policy = new QueryPolicy(); List <string> list = new List <string>(); list.Add("A"); list.Add("C"); policy.filterExp = Exp.Build( Exp.EQ( ListExp.Size( // return type VALUE returns a list MapExp.GetByKeyList(MapReturnType.VALUE, Exp.Val(list), Exp.MapBin("mapbin"))), Exp.Val(2))); RecordSet rs = client.Query(policy, stmt); try { int count = 0; while (rs.Next()) { //Console.WriteLine(rs.Record.ToString()); count++; } Assert.AreEqual(1, count); } finally { rs.Close(); } }
private void Describe(Key key) { Exp index = Exp.Val(0); policy.filterExp = Exp.Build( Exp.NE( ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin1))), ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin2))))); Record r = client.Get(policy, key); Assert.AreEqual(null, r); policy.filterExp = Exp.Build( Exp.EQ( ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin1))), ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin2))))); r = client.Get(policy, key); AssertRecordFound(key, r); }
public void QueryList2() { int begin = 1; int end = 10; Statement stmt = new Statement(); stmt.SetNamespace(args.ns); stmt.SetSetName(setName); stmt.SetFilter(Filter.Range(binName, begin, end)); // List bin does not contain integer item == 5 QueryPolicy policy = new QueryPolicy(); policy.filterExp = Exp.Build( Exp.EQ( ListExp.GetByValue(ListReturnType.COUNT, Exp.Val(5), Exp.ListBin("listbin")), Exp.Val(0))); RecordSet rs = client.Query(policy, stmt); try { int count = 0; while (rs.Next()) { //Console.WriteLine(rs.Record.ToString()); count++; } Assert.AreEqual(8, count); } finally { rs.Close(); } }
public void QueryList3() { int begin = 1; int end = 10; Statement stmt = new Statement(); stmt.SetNamespace(args.ns); stmt.SetSetName(setName); stmt.SetFilter(Filter.Range(binName, begin, end)); // list[4] == 20 QueryPolicy policy = new QueryPolicy(); policy.filterExp = Exp.Build( Exp.EQ( ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, Exp.Val(4), Exp.ListBin("listbin")), Exp.Val(20))); RecordSet rs = client.Query(policy, stmt); try { int count = 0; while (rs.Next()) { //Console.WriteLine(rs.Record.ToString()); count++; } Assert.AreEqual(1, count); } finally { rs.Close(); } }
public virtual bool Accepts(ListExp exp) { return(false); }
public void ModifyWithContext() { IList <Value> listSubA = new List <Value>(); listSubA.Add(Value.Get("e")); listSubA.Add(Value.Get("d")); listSubA.Add(Value.Get("c")); listSubA.Add(Value.Get("b")); listSubA.Add(Value.Get("a")); IList <Value> listA = new List <Value>(); listA.Add(Value.Get("a")); listA.Add(Value.Get("b")); listA.Add(Value.Get("c")); listA.Add(Value.Get("d")); listA.Add(Value.Get(listSubA)); IList <Value> listB = new List <Value>(); listB.Add(Value.Get("x")); listB.Add(Value.Get("y")); listB.Add(Value.Get("z")); client.Operate(null, keyA, ListOperation.AppendItems(ListPolicy.Default, binA, (IList)listA), ListOperation.AppendItems(ListPolicy.Default, binB, (IList)listB), Operation.Put(new Bin(binC, "M")) ); CTX ctx = CTX.ListIndex(4); Record record; IList result; policy.filterExp = Exp.Build( Exp.EQ( ListExp.Size( // Temporarily Append binB/binC to binA in expression. ListExp.AppendItems(ListPolicy.Default, Exp.ListBin(binB), ListExp.Append(ListPolicy.Default, Exp.StringBin(binC), Exp.ListBin(binA), ctx), ctx), ctx), Exp.Val(9))); record = client.Get(policy, keyA, binA); AssertRecordFound(keyA, record); result = record.GetList(binA); Assert.AreEqual(5, result.Count); policy.filterExp = Exp.Build( Exp.EQ( ListExp.Size( // Temporarily Append local listB and local "M" string to binA in expression. ListExp.AppendItems(ListPolicy.Default, Exp.Val((IList)listB), ListExp.Append(ListPolicy.Default, Exp.Val("M"), Exp.ListBin(binA), ctx), ctx), ctx), Exp.Val(9))); record = client.Get(policy, keyA, binA); AssertRecordFound(keyA, record); result = record.GetList(binA); Assert.AreEqual(5, result.Count); }
public void OnList(ListExp exp) { }
/// <summary> /// Create expression that selects list items identified by value range and returns selected data /// specified by returnType. /// </summary> /// <example> /// <code> /// // List bin "a" items >= 10 && items < 20 /// ListExp.GetByValueRange(ListReturnType.VALUE, Exp.Val(10), Exp.Val(20), Exp.ListBin("a")) /// </code> /// </example> /// <param name="returnType">metadata attributes to return. See <see cref="ListReturnType"/></param> /// <param name="valueBegin">begin expression inclusive. If null, range is less than valueEnd.</param> /// <param name="valueEnd">end expression exclusive. If null, range is greater than equal to valueBegin.</param> /// <param name="bin">bin or list value expression</param> /// <param name="ctx">optional context path for nested CDT</param> public static Exp GetByValueRange(ListReturnType returnType, Exp valueBegin, Exp valueEnd, Exp bin, params CTX[] ctx) { byte[] bytes = ListExp.PackRangeOperation(ListOperation.GET_BY_VALUE_INTERVAL, (int)returnType, valueBegin, valueEnd, ctx); return(AddRead(bin, bytes, GetValueType(returnType))); }
/// <summary> /// Create expression that removes list items identified by value range (valueBegin inclusive, valueEnd exclusive). /// If valueBegin is null, the range is less than valueEnd. If valueEnd is null, the range is /// greater than equal to valueBegin. /// </summary> public static Exp RemoveByValueRange(Exp valueBegin, Exp valueEnd, Exp bin, params CTX[] ctx) { byte[] bytes = ListExp.PackRangeOperation(ListOperation.REMOVE_BY_VALUE_INTERVAL, (int)ListReturnType.NONE, valueBegin, valueEnd, ctx); return(AddWrite(bin, bytes, ctx)); }
/// <summary> /// Create expression that selects map items identified by key range (keyBegin inclusive, keyEnd exclusive). /// If keyBegin is null, the range is less than keyEnd. /// If keyEnd is null, the range is greater than equal to keyBegin. /// <para> /// Expression returns selected data specified by returnType. /// </para> /// </summary> public static Exp GetByKeyRange(MapReturnType returnType, Exp keyBegin, Exp keyEnd, Exp bin, params CTX[] ctx) { byte[] bytes = ListExp.PackRangeOperation(MapOperation.GET_BY_KEY_INTERVAL, (int)returnType, keyBegin, keyEnd, ctx); return(AddRead(bin, bytes, GetValueType(returnType))); }
/// <summary> /// Create expression that removes map items identified by key range (keyBegin inclusive, keyEnd exclusive). /// If keyBegin is null, the range is less than keyEnd. /// If keyEnd is null, the range is greater than equal to keyBegin. /// </summary> public static Exp RemoveByKeyRange(Exp keyBegin, Exp keyEnd, Exp bin, params CTX[] ctx) { byte[] bytes = ListExp.PackRangeOperation(MapOperation.REMOVE_BY_KEY_INTERVAL, (int)MapReturnType.NONE, keyBegin, keyEnd, ctx); return(AddWrite(bin, bytes, ctx)); }
public virtual Expression OnList(ListExp exp) { return(builder.CreateList(exp.exp.Visit(this))); }
public override void GetNestedFields(Dictionary <string, VarExp> nestedField) { ListExp.GetNestedFields(nestedField); }
public override Expression OnList(ListExp exp) { return(Expression.NotAllowed); }