Ejemplo n.º 1
0
        public override Expression VisitMethodCall(MethodCall mc)
        {
            Expression result = base.VisitMethodCall(mc);

            mc = result as MethodCall;
            // check for Aggregate types
            if (mc != null && mc.Operands != null && mc.Operands.Count == 1)
            {
                Literal lit = mc.Callee as Literal;
                if (lit != null && lit.Type == SystemTypes.Type)
                {
                    TypeNode type = (TypeNode)lit.Value;
                    if (type != null && type.IsAssignableTo(SystemTypes.IAggregateGroup))
                    {
                        QueryAggregate qa = new QueryAggregate();
                        qa.Name          = type.Name;
                        qa.AggregateType = type;
                        qa.Expression    = mc.Operands[0];
                        qa.SourceContext = mc.SourceContext;
                        if (this.currentGroup != null)
                        {
                            this.currentGroup.AggregateList.Add(qa);
                            qa.Group = this.currentGroup;
                        }
                        return(qa);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public override Node VisitQueryAggregate(QueryAggregate qa)
        {
            base.VisitQueryAggregate(qa);
            Composer c = this.GetComposer(qa.Expression);

            return(this.Compose(qa, c));
        }
Ejemplo n.º 3
0
 // query nodes
 public virtual Node VisitQueryAggregate(QueryAggregate qa, QueryAggregate changes, QueryAggregate deletions, QueryAggregate insertions){
   this.UpdateSourceContext(qa, changes);
   if (qa == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return qa;
 }
Ejemplo n.º 4
0
 public override Expression VisitMethodCall(MethodCall mc){
   Expression result = base.VisitMethodCall(mc);
   mc = result as MethodCall;
   // check for Aggregate types
   if (mc != null && mc.Operands != null && mc.Operands.Count == 1) {
     Literal lit = mc.Callee as Literal;
     if (lit != null && lit.Type == SystemTypes.Type) {
       TypeNode type = (TypeNode) lit.Value;
       if (type != null && type.IsAssignableTo(SystemTypes.IAggregateGroup)) {
         QueryAggregate qa = new QueryAggregate();
         qa.Name = type.Name;
         qa.AggregateType = type;
         qa.Expression = mc.Operands[0];
         qa.SourceContext = mc.SourceContext;
         if (this.currentGroup != null) {
           this.currentGroup.AggregateList.Add(qa);
           qa.Group = this.currentGroup;
         }
         return qa;      
       }
     }
   }
   return result;
 }
Ejemplo n.º 5
0
    // query nodes
    public virtual Differences VisitQueryAggregate(QueryAggregate qa1, QueryAggregate qa2){
      Differences differences = new Differences(qa1, qa2);
      if (qa1 == null || qa2 == null){
        if (qa1 != qa2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryAggregate changes = (QueryAggregate)qa2.Clone();
      QueryAggregate deletions = (QueryAggregate)qa2.Clone();
      QueryAggregate insertions = (QueryAggregate)qa2.Clone();

      Differences diff = this.VisitTypeNode(qa1.AggregateType, qa2.AggregateType);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.AggregateType = diff.Changes as TypeNode;
      deletions.AggregateType = diff.Deletions as TypeNode;
      insertions.AggregateType = diff.Insertions as TypeNode;
      //Debug.Assert(diff.Changes == changes.AggregateType && diff.Deletions == deletions.AggregateType && diff.Insertions == insertions.AggregateType);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(qa1.Expression, qa2.Expression);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Expression = diff.Changes as Expression;
      deletions.Expression = diff.Deletions as Expression;
      insertions.Expression = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Expression && diff.Deletions == deletions.Expression && diff.Insertions == insertions.Expression);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitQueryGroupBy(qa1.Group, qa2.Group);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Group = diff.Changes as QueryGroupBy;
      deletions.Group = diff.Deletions as QueryGroupBy;
      insertions.Group = diff.Insertions as QueryGroupBy;
      Debug.Assert(diff.Changes == changes.Group && diff.Deletions == deletions.Group && diff.Insertions == insertions.Group);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitIdentifier(qa1.Name, qa2.Name);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Name = diff.Changes as Identifier;
      deletions.Name = diff.Deletions as Identifier;
      insertions.Name = diff.Insertions as Identifier;
      Debug.Assert(diff.Changes == changes.Name && diff.Deletions == deletions.Name && diff.Insertions == insertions.Name);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Ejemplo n.º 6
0
 // query nodes
 public virtual Node VisitQueryAggregate(QueryAggregate qa){
   if (qa == null) return null;
   qa.Expression = this.VisitExpression(qa.Expression);
   return qa;
 }
Ejemplo n.º 7
0
 private QueryAggregate CheckQueryAggregate(QueryAggregate qa) {
   if (qa == null) return null;
   if (qa.Expression == null || qa.Expression.Type == null) return null;
   if (qa.Context != null && qa.Group == null) {
     Cardinality card = this.typeSystem.GetCardinality(qa.Expression, this.TypeViewer);
     if (card == Cardinality.OneOrMore && card == Cardinality.ZeroOrMore) {
       this.HandleError(qa.Expression, Error.QueryNotScalar);
       return null;
     }
   }
   MemberList members = this.GetTypeView(qa.AggregateType).GetMembersNamed(StandardIds.Add);
   if (members == null || members.Count == 0) {
     this.HandleError(qa, Error.QueryBadAggregateForm, qa.Name.Name);
     return null;
   }
   Method madd = members[0] as Method;
   if (madd == null || madd.Parameters == null || madd.Parameters.Count != 1) {
     this.HandleError(qa, Error.QueryBadAggregateForm, qa.Name.Name);
     return null;
   }
   TypeNode coreType = this.typeSystem.GetStreamElementType(qa.Expression, this.TypeViewer);
   if (!this.typeSystem.ImplicitCoercionFromTo(coreType, madd.Parameters[0].Type, this.TypeViewer)) {
     this.HandleError(qa, Error.QueryBadAggregate, qa.Name.Name, this.GetTypeName(coreType));
     return null;
   }
   Method mgetvalue = qa.AggregateType.GetMethod(StandardIds.GetValue);
   if (mgetvalue == null) {
     this.HandleError(qa, Error.QueryBadAggregateForm, qa.Name.Name);
     return null;
   }
   if (qa.Type == null) return null;
   return qa;
 }
Ejemplo n.º 8
0
 public override Node VisitQueryAggregate(QueryAggregate qa) {
   if (qa == null) return null;
   qa.Expression = this.VisitExpression(qa.Expression);
   return this.CheckQueryAggregate(qa);
 }
Ejemplo n.º 9
0
 public override Node VisitQueryAggregate(QueryAggregate qa){
   if (qa == null) return null;
   qa.Context = this.contextScope;
   if (qa.Group == null){
     qa.Expression = this.VisitExpression(qa.Expression);
     TypeNode inputType = this.typeSystem.GetStreamElementType(qa.Expression, this.TypeViewer);
     TypeNode aggType = this.GetAggregateSubType(qa.AggregateType, inputType);
     if (aggType == null) return qa;
     qa.AggregateType = aggType;
     Method mgetval = this.GetTypeView(aggType).GetMethod(StandardIds.GetValue);
     if (mgetval != null){
       qa.Type = mgetval.ReturnType;
     }
   }
   return qa;
 }
Ejemplo n.º 10
0
 // query nodes
 public virtual void VisitQueryAggregate(QueryAggregate qa){
   if (qa == null) return;
   this.VisitExpression(qa.Expression);
 }
Ejemplo n.º 11
0
 // query nodes
 public override Node VisitQueryAggregate(QueryAggregate qa){
   if (qa == null) return null;
   return base.VisitQueryAggregate((QueryAggregate)qa.Clone());
 }
Ejemplo n.º 12
0
 // query nodes
 public virtual Node VisitQueryAggregate(QueryAggregate qa1, QueryAggregate qa2){
   if (qa1 == null) return null;
   if (qa2 == null)
     qa1.Expression = this.VisitExpression(qa1.Expression, null);
   else
     qa1.Expression = this.VisitExpression(qa1.Expression, qa2.Expression);
   return qa1;
 }
Ejemplo n.º 13
0
 public override Node VisitQueryAggregate(QueryAggregate qa) {
   BlockScope scope = this.currentMethod.Body.Scope;
   TypeNode aggType = qa.AggregateType;
   if (qa.Group != null) {
     // find field offset in result
     Field f = null;
     for (int i = 0, n = qa.Group.AggregateList.Count; i < n; i++) {
       if (qa.UniqueKey == qa.Group.AggregateList[i].UniqueKey) {
         int offset = qa.Group.GroupList.Count + i;
         f = qa.Context.Type.Members[offset] as Field;
         break;
       }
     }
     Expression mb = new MemberBinding(new QueryContext(qa.Context), f);
     mb.Type = f.Type;
     return this.VisitExpression(mb);
   }
   else {
     Block block = new Block(new StatementList(4));
     Local locAgg = new Local(aggType);
     if (!aggType.IsValueType) {
       Construct cons = new Construct();
       cons.Constructor = new MemberBinding(null, this.GetTypeView(aggType).GetConstructor());
       cons.Type = aggType;
       block.Statements.Add(new AssignmentStatement(locAgg, cons));
     }
     Block inner = null;
     Expression val = new Local(this.typeSystem.GetStreamElementType(qa.Expression, this.TypeViewer));
     block.Statements.Add(this.BuildClosureForEach(qa.Expression, ref val, out inner, scope));
     // add target to aggregate
     Method madd = this.GetTypeView(aggType).GetMembersNamed(StandardIds.Add)[0] as Method;
     val = this.typeSystem.ExplicitCoercion(val, madd.Parameters[0].Type, this.TypeViewer);
     MethodCall mcadd = new MethodCall(new MemberBinding(locAgg, madd), new ExpressionList(val));
     mcadd.Type = madd.ReturnType;
     inner.Statements.Add(new ExpressionStatement(mcadd));
     // get result value
     Method mgetval = this.GetTypeView(aggType).GetMethod(StandardIds.GetValue);
     MethodCall mcgetval = new MethodCall(new MemberBinding(locAgg, mgetval), null);
     mcgetval.Type = mgetval.ReturnType;
     block.Statements.Add(new ExpressionStatement(mcgetval));
     BlockExpression be = new BlockExpression(block, qa.Type);
     return this.VisitBlockExpression(be);
   }
 }
Ejemplo n.º 14
0
 public override Node VisitQueryAggregate( QueryAggregate qa ){
   base.VisitQueryAggregate(qa);
   if (qa.Group != null && this.currentGroup != null){
     this.currentGroup.AggregateList.Add(qa);
     qa.Group = this.currentGroup;
   }
   return qa;
 }
Ejemplo n.º 15
0
 public override Node VisitQueryAggregate(QueryAggregate qa) {
   base.VisitQueryAggregate(qa);
   Composer c = this.GetComposer(qa.Expression);
   return this.Compose(qa, c);
 }
Ejemplo n.º 16
0
 public EventingVisitor(Action<QueryAggregate> visitQueryAggregate) { VisitedQueryAggregate += visitQueryAggregate; } public event Action<QueryAggregate> VisitedQueryAggregate; public override Node VisitQueryAggregate(QueryAggregate qa) { if (VisitedQueryAggregate != null) VisitedQueryAggregate(qa); return base.VisitQueryAggregate(qa); }