Exemplo n.º 1
0
 // Nothing to resolve for literal expressions
 protected override Exp ResolveExpAsRight(ISemanticResolver s)
 {   
     // Always resolve our children     
     ResolveExpAsRight(ref m_left, s);
     ResolveExpAsRight(ref m_right, s);
     
     // If we don't match a predefined operator, then check for overloads
     if (!MatchesPredefinedOp(Op, this.Left.CLRType, this.Right.CLRType))
     {
         // Packagage Left & Right into parameters for a method call
         ArgExp [] args = new ArgExp [2] {
             new ArgExp(EArgFlow.cIn, m_left),
             new ArgExp(EArgFlow.cIn, m_right)
         };
                                 
         // Check for delegate combination
         // D operator+(D, D)
         // D operator-(D, D)            
         if (AST.DelegateDecl.IsDelegate(m_left.CLRType))
         {
             if (m_left.CLRType == m_right.CLRType)
             {
                 if (Op == BinaryOp.cAdd || Op == BinaryOp.cSub)
                 {
                     System.Type d = m_left.CLRType;
                     
                     // Translates to:
                     // op+ --> (D) System.Delegate.Combine(left, right)
                     // op- --> (D) System.Delegate.Remove(left, right)
                     
                     TypeEntry tDelegate = s.LookupSystemType("MulticastDelegate");
                     string stName = (Op == BinaryOp.cAdd) ? "Combine" : "Remove";
                     
                     bool dummy;
                     MethodExpEntry sym = tDelegate.LookupMethod(s, new Identifier(stName), 
                         new Type[] { d, d}, out dummy);
                     
                     
                     Exp call2 = new CastObjExp(
                         new ResolvedTypeSig(d, s),
                         new MethodCallExp(
                             null,sym, args, s)
                     );
                     
                     Exp.ResolveExpAsRight(ref call2, s);
                     return call2;                                
                 
                 }
             }
         
         } // end delgate op+ check
                                         
         // Check for System.String.Concat().
         // @todo - this should be able to compress an entire subtree, not just 2 args.
         // (ie, a+b+c -> String.Concat(a,b,c);
         // So we can't merge this into the SearchForOverload.
         // But for now we'll be lazy...
         if ((Op == BinaryOp.cAdd) && (Left.CLRType == typeof(string) || Right.CLRType == typeof(string)))
         {                
             Exp call2 = new MethodCallExp(                    
                     new DotObjExp(
                         new SimpleObjExp(
                             new Identifier("System", this.m_filerange)
                         ),
                         new Identifier("String", this.m_filerange)),
                     new Identifier("Concat", m_filerange),
                     args);
             call2.SetLocation(this.Location);
             Exp.ResolveExpAsRight(ref call2, s);
                     
             return call2;
         }
     
         MethodExpEntry  m = SearchForOverloadedOp(s);
         if (m == null && (Op == BinaryOp.cEqu || Op == BinaryOp.cNeq))
         {
             // If it's '==' or '!=', then it's ok if we didn't find 
             // an overload.
         } else 
         {
             // Couldn't find an overload, throw error
             if (m == null)
             {
                 //ThrowError_NoAcceptableOperator(s, this.Location, m_left.CLRType, m_right.CLRType, Op);
                 ThrowError(SymbolError.NoAcceptableOperator(this.Location, m_left.CLRType, m_right.CLRType, Op));
             }
             
             // Replace this node w/ the method call            
             MethodCallExp call = new MethodCallExp(null, m, args, s);
             call.SetLocation(this.Location);
             
             return call;
         }
     }
     
     
     CalcCLRType(s);
     
     return this;
 }