Esempio n. 1
0
 public override Expression VisitImplicitThis(ImplicitThis implicitThis)
 {
     if (this._string == null)
     {
         this._string = new StringBuilder();
     }
     if (this.currentClosureLocal == null)
     {
         this._string.Append("this");
     }
     else
     {
         this.Visit(this.currentClosureLocal);
     }
     return(implicitThis);
 }
Esempio n. 2
0
 public virtual Expression VisitImplicitThis(ImplicitThis implicitThis, ImplicitThis changes, ImplicitThis deletions, ImplicitThis insertions){
   this.UpdateSourceContext(implicitThis, changes);
   if (implicitThis == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return implicitThis;
 }
 public virtual Differences VisitImplicitThis(ImplicitThis implicitThis1, ImplicitThis implicitThis2){
   Differences differences = new Differences(implicitThis1, implicitThis2);
   if (implicitThis1 == null || implicitThis2 == null){
     if (implicitThis1 != implicitThis2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
   }else{
     differences.NumberOfSimilarities++;
     differences.Changes = null;
   }
   return differences;
 }
Esempio n. 4
0
 public virtual Expression VisitImplicitThis(ImplicitThis implicitThis){
   return implicitThis;
 }
Esempio n. 5
0
    public override Expression VisitConstruct(Construct cons){
      if (cons == null) return cons;
      cons.Owner = this.VisitExpression(cons.Owner);
      cons.Constructor = this.VisitExpression(cons.Constructor);
      MemberBinding mb = cons.Constructor as MemberBinding;
      if (mb == null){
        Literal literal = cons.Constructor as Literal;
        if (literal == null) return cons;
        TypeNode t = literal.Value as TypeNode;
        if (t == null) return cons;
        cons.Type = t;
        cons.Constructor = mb = new MemberBinding(null, t);
        mb.SourceContext = literal.SourceContext;
      }else{
        TypeNode t = mb.BoundMember as TypeNode;
        if (t == null) return cons; //TODO: if the bound member is an instance initializer, use it.
        cons.Type = t;
      }
      AnonymousNestedFunction func = null;
      DelegateNode delType = cons.Type as DelegateNode;
      if (delType != null && cons.Operands != null && cons.Operands.Count == 1){
        Method meth = null;
        Expression ob = Literal.Null;
        Expression e = cons.Operands[0];
        MemberBinding emb = e as MemberBinding;
        if (emb != null) e = emb.BoundMemberExpression;
        TemplateInstance instance = e as TemplateInstance;
        TypeNodeList typeArguments = instance == null ? null : instance.TypeArguments;
        if (instance != null) e = instance.Expression;
        NameBinding nb = e as NameBinding;
        if (nb != null){
          meth = this.ChooseMethodMatchingDelegate(nb.BoundMembers, delType, typeArguments);
          if (meth != null && !meth.IsStatic)
            ob = new ImplicitThis();
          else if (meth == null){
            e = this.VisitExpression(e);
            if (e.Type is DelegateNode){
              meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(e.Type).GetMembersNamed(StandardIds.Invoke), delType, typeArguments);
              if (meth != null)
                ob = e;
            }
          }
        }else{
          QualifiedIdentifier qualId = e as QualifiedIdentifier;
          if (qualId != null){
            ob = qualId.Qualifier = this.VisitExpression(qualId.Qualifier);
            if (ob is Literal && ob.Type == SystemTypes.Type)
              meth = this.ChooseMethodMatchingDelegate(this.GetTypeView((ob as Literal).Value as TypeNode).GetMembersNamed(qualId.Identifier), delType, typeArguments);
            else if (ob == null)
              return null;
            else if (ob != null && ob.Type != null){
              TypeNode oT = TypeNode.StripModifiers(ob.Type);
              Reference rT = oT as Reference;
              if (rT != null) oT = rT.ElementType;
              while (oT != null){
                meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(oT).GetMembersNamed(qualId.Identifier), delType, typeArguments);
                if (meth != null) break;
                oT = oT.BaseType;
              }
            }
            if (meth == null){
              e = this.VisitExpression(e);
              if (e.Type is DelegateNode){
                meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(e.Type).GetMembersNamed(StandardIds.Invoke), delType, typeArguments);
                if (meth != null){
                  qualId.BoundMember = new MemberBinding(e, meth, qualId.Identifier);
                  ob = e;
                }
              }
            }else
              qualId.BoundMember = new MemberBinding(ob, meth, qualId.Identifier);
          }else{
            func = e as AnonymousNestedFunction;
            if (func != null){
              meth = func.Method;
              if (meth != null){
                meth.ReturnType = delType.ReturnType;
                ParameterList mParams = meth.Parameters;
                ParameterList dParams = delType.Parameters;
                int n = mParams == null ? 0 : mParams.Count;
                int m = dParams == null ? 0 : dParams.Count;
                for (int i = 0; i < n; i++){
                  Parameter mPar = mParams[i];
                  if (mPar == null) return null;
                  if (i >= m){
                    if (mPar.Type == null) mPar.Type = SystemTypes.Object;
                    continue;
                  }
                  Parameter dPar = dParams[i];
                  if (mPar.Type == null){
                    if (dPar != null)
                      mPar.Type = dPar.Type;
                    if (mPar.Type == null)
                      mPar.Type = SystemTypes.Object;
                  }
                }
                if (n != m){
                  Node nde = new Expression(NodeType.Nop);
                  if (n == 0)
                    nde.SourceContext = cons.Constructor.SourceContext;
                  else{
                    nde.SourceContext = mParams[0].SourceContext;
                    nde.SourceContext.EndPos = mParams[n-1].SourceContext.EndPos;
                  }
                  this.HandleError(nde, Error.WrongNumberOfArgumentsForDelegate, this.GetTypeName(delType), n.ToString());
                  return null;
                }
                MemberList mems = meth.Scope == null ? null : meth.Scope.Members;
                n = mems == null ? 0 : mems.Count;
                for (int i = 0; i < n; i++){
                  ParameterField f = mems[i] as ParameterField;
                  if (f == null) continue;
                  Parameter p = f.Parameter;
                  if (p != null) f.Type = p.Type;
                }
                func = this.VisitAnonymousNestedFunction(func) as AnonymousNestedFunction;
                if (func == null) return null;
                meth = func.Method;
                if (meth == null || meth.DeclaringType == null) return null;
                ob = new CurrentClosure(meth, meth.DeclaringType);
              }
            }
          }
        }
        if (meth != null){
          Expression ldftn = null;
          MemberBinding memb = new MemberBinding(null, meth, e);
          memb.Type = null; //Signal to Checker not to complain about this reference to a method without parenthesis
          if (meth.IsVirtualAndNotDeclaredInStruct)
            ldftn = new BinaryExpression(new Expression(NodeType.Dup), memb, NodeType.Ldvirtftn);
          else{
            if (meth.IsStatic) ob = Literal.Null;
            ldftn = new UnaryExpression(memb, NodeType.Ldftn);
          }
          ldftn.Type = SystemTypes.IntPtr;
          ExpressionList arguments = cons.Operands = new ExpressionList(2);
          arguments.Add(ob);
          arguments.Add(ldftn);
          if (ob is ImplicitThis && this.currentMethod != null && this.currentMethod.IsStatic &&
            !(this.currentMethod.Scope.CapturedForClosure && meth.DeclaringType == this.currentMethod.Scope.ClosureClass)){
            this.HandleError(e, Error.ObjectRequired, this.GetMemberSignature(meth));
            return null;
          }
        }else{
          cons.Constructor = new Literal(delType);
          return cons;
        }
      }else{
        cons.Operands = this.VisitExpressionList(cons.Operands);
        UnaryExpression op2nd = cons.Operands != null && cons.Operands.Count > 1 ?
          cons.Operands[1] as UnaryExpression : null;
        if (op2nd != null){
          MemberBinding mb2nd = op2nd.Operand as MemberBinding;
          if (mb2nd != null && mb2nd.BoundMember is Method) mb2nd.Type = null;
        }
      }
      
      MemberList members = this.GetTypeView(cons.Type).GetConstructors();
      Method method = this.ResolveOverload(members, cons.Operands) as Method;
     
      if (method == null && cons.Operands != null && cons.Operands.Count == 1){
        Comprehension q = cons.Operands[0] as Comprehension;
        if (q == null) goto End;
        
        Method m2 = this.ResolveOverload(members, new ExpressionList()) as Method;
        //Method m2 = this.GetTypeView(cons.Type).GetConstructor(); // see if there is a nullary .ctor
        if (m2 == null && cons.Type.NodeType == NodeType.Class) goto End;
        TypeNode qType = TypeNode.StripModifiers(q.Type);
        if (q.Elements == null || qType== null || qType.TemplateArguments==null || qType.TemplateArguments.Count==0) goto End;

        if (this.GetTypeView(cons.Type).IsAssignableTo(SystemTypes.IList)){
          method = m2;
          q.AddMethod = SystemTypes.IList.GetMethod(StandardIds.Add,SystemTypes.Object);
        } else if ((q.Elements.Count == 0 || this.GetTypeView(qType.TemplateArguments[0]).IsAssignableTo(SystemTypes.DictionaryEntry)) && this.GetTypeView(cons.Type).IsAssignableTo(SystemTypes.IDictionary)) {
          method = m2;
          q.AddMethod = SystemTypes.IDictionary.GetMethod(StandardIds.Add,SystemTypes.Object,SystemTypes.Object);
        } else if (((q.Elements.Count == 0 || this.GetTypeView(qType.TemplateArguments[0]).IsAssignableTo(SystemTypes.DictionaryEntry)) && 
          (q.AddMethod = this.GetTypeView(cons.Type).GetMethod(StandardIds.Add,SystemTypes.Object, SystemTypes.Object)) != null) && 
          q.AddMethod.ReturnType == SystemTypes.Void){
          method = m2;
        } else if ((q.AddMethod = this.GetTypeView(cons.Type).GetMethod(StandardIds.Add,SystemTypes.Object)) != null &&
          q.AddMethod.ReturnType == SystemTypes.Int32){
          method = m2;
        } else
          q.AddMethod = null;

        // NB: if m2 is assigned to method, then the actual .ctor does *not* match the operands
        // but the Normalizer will compensate for it.
        // 2nd disjunct: don't need a .ctor method to construct a struct

        if ((method != null || cons.Type.NodeType == NodeType.Struct) && q.AddMethod!= null){
          // The Comprehension is going to replace the expression "new T{...}",
          // so it better have the same type
          // But Checker needs the T in the IEnumerable<T> that is sitting in q.Type, so
          // need a place to put it so Checker can find it. REVIEW!!!
          q.TemporaryHackToHoldType = q.Type;
          q.Type = cons.Type;
          if (method != null)
            q.nonEnumerableTypeCtor = method;
          else
            q.nonEnumerableTypeCtor = cons.Type;
          return q;
        }
      }
    End:
      
      if (method != null && method.DeclaringType == cons.Type){
        cons.Constructor = mb;
        mb.BoundMember = method;
      }
      if (cons != null) {
        Method m = method;
        if (m == null && members != null && members.Count > 0)
          m = members[0] as Method;
        if(m != null)
          this.ParameterPreselectionProcessing(m.Parameters, cons.Operands);
      }
      if (func != null){
        func.Invocation = cons;
        func.Type = cons.Type;
        return func;
      }
      if (cons.Type != null && !cons.Type.IsValueType && this.NonNullChecking)
        cons.Type = OptionalModifier.For(SystemTypes.NonNullType, cons.Type);
      return cons;
    }
Esempio n. 6
0
 public override Expression VisitImplicitThis(ImplicitThis This){
   if (This == null) return null;
   TypeNode currentType = this.currentTypeInstance;
   if (currentType == null)
     This.Type = SystemTypes.Object;
   else{
     if (currentType.IsValueType)
       This.Type = currentType.GetReferenceType();
     else
       This.Type = currentType;
   }
   return This;
 }
Esempio n. 7
0
 public virtual void VisitImplicitThis(ImplicitThis implicitThis)
 {
 }
 public override Expression VisitImplicitThis(ImplicitThis implicitThis)
 {
   throw new ApplicationException("unimplemented");
 }
Esempio n. 9
0
 public override Expression VisitImplicitThis(ImplicitThis implicitThis) {
   if (this._string == null){ this._string = new StringBuilder(); }
   if (this.currentClosureLocal == null) {
     this._string.Append("this");
   } else {
     this.Visit(this.currentClosureLocal);
   }
   return implicitThis;
 }
Esempio n. 10
0
 public override Expression VisitImplicitThis(ImplicitThis implicitThis)
 {
     if (implicitThis == null) return null;
     return base.VisitImplicitThis((ImplicitThis)implicitThis.Clone());
 }
Esempio n. 11
0
 public virtual Expression VisitImplicitThis(ImplicitThis implicitThis1, ImplicitThis implicitThis2)
 {
     return implicitThis1;
 }
Esempio n. 12
0
 public override Node VisitQueryContext(QueryContext qc) {
   if (qc == null || qc.Scope == null) return null;
   MemberBinding mb = qc.Scope.Target as MemberBinding;
   if (mb != null) {
     ImplicitThis imp = new ImplicitThis(); imp.Type = mb.BoundMember.DeclaringType;
     MemberBinding cmb = new MemberBinding(imp, mb.BoundMember);
     return this.VisitExpression(cmb);
   }
   return this.VisitExpression(qc.Scope.Target);
 }
Esempio n. 13
0
 public virtual Node EndQueryClosure(Node closure, TypeNode collectionType) {
   CurrentClosure cc = closure as CurrentClosure;
   if (cc != null) {
     this.EndCurrentClosure(cc);
     ImplicitThis it = new ImplicitThis();
     it.Type = cc.Method.DeclaringType;
     MethodCall mc = new MethodCall(new MemberBinding(it, cc.Method), null);
     mc.Type = cc.Method.ReturnType;
     return this.VisitExpression(this.typeSystem.ExplicitCoercion(mc, collectionType, this.TypeViewer));
   }
   return closure;  // don't visit here.  These nodes will be visited by QueryYielder
 }
Esempio n. 14
0
 public virtual Block BuildAxisClosure(Expression source, AxisBuildState state, Accessor acc, BlockScope scope) {
   if (state.TypeClosures != null) {
     TypeNode tn = source.Type;
     CurrentClosure cc = (CurrentClosure) state.TypeClosures[tn.UniqueKey];
     if (cc == null) {
       cc = this.BeginCurrentClosure(state.YieldType, "axis");
       Parameter p = new Parameter(Identifier.For("source"), tn);
       cc.Method.Parameters = new ParameterList(1);
       cc.Method.Parameters.Add(p);
       state.TypeClosures[tn.UniqueKey] = cc;
       ParameterField pf = new ParameterField(cc.Method.Scope, null, FieldFlags.Public, p.Name, p.Type, null);
       pf.Parameter = p;
       cc.Method.Scope.Members.Add(pf);
       MemberBinding mb = new MemberBinding(new ImplicitThis(), pf);
       mb.Type = pf.Type;
       cc.Method.Body.Statements.Add(this.BuildAxisClosureBlock(mb, state, acc, cc.Method.Body.Scope));
       this.EndCurrentClosure(cc);
     }
     Block block = new Block(new StatementList(1));
     ImplicitThis it = new ImplicitThis();
     it.Type = cc.Method.DeclaringType;
     MethodCall mc = new MethodCall(new MemberBinding(it, cc.Method), new ExpressionList(source));
     mc.Type = cc.Method.ReturnType;
     if (cc.Method.IsVirtual) mc.NodeType = NodeType.Callvirt;
     Expression target = null;
     Block inner = null;
     block.Statements.Add(this.BuildClosureForEach(mc, ref target, out inner, scope));
     inner.Statements.Add(new Yield(target));
     return block;
   }
   return this.BuildAxisClosureBlock(source, state, acc, scope);
 }
Esempio n. 15
0
 public override Expression VisitImplicitThis(ImplicitThis implicitThis){
   Expression result = this.currentClosureLocal;
   if (result == null) return this.currentThisParameter;
   return this.GetBindingPath(result, implicitThis.Type);
 }
Esempio n. 16
0
 public override Expression VisitImplicitThis(ImplicitThis implicitThis)
 {
     throw new ApplicationException("unimplemented");
 }