Пример #1
0
        /// <summary>
        /// Creates a new <see cref="CSharpRelationalExpression"/> instance with the
        /// <paramref name="leftSide"/>, <paramref name="operation"/>, and <paramref name="rightSide"/>
        /// provided.
        /// </summary>
        /// <param name="leftSide">The <see cref="ICSharpRelationalExpression"/>
        /// which sits on the left side of <paramref name="operation"/>.</param>
        /// <param name="operation">The <see cref="CSharpRelationalOperation"/> to be performed
        /// with regards to <paramref name="leftSide"/> and <paramref name="rightSide"/>.</param>
        /// <param name="rightSide">The <see cref="ICSharpShiftExpression"/>
        /// which sits on the right-side of <paramref name="operation"/>.</param>
        /// <exception cref="System.ArgumentNullException">thrown when <paramref name="rightSide"/> is null, or when
        /// <paramref name="leftSide"/> is null and <paramref name="operation"/> is not
        /// <see cref="CSharpRelationalOperation.Term"/>.</exception>
        /// <exception cref="System.ArgumentException">thrown when <paramref name="operation"/> is
        /// <see cref="CSharpRelationalOperation.TypeCastOrNull"/> or <see cref="CSharpRelationalOperation.TypeCheck"/>
        /// and <paramref name="rightSide"/> does not <see cref="CSharpExpressionExtensions.Detach(IExpression)"/>
        /// to an <see cref="ITypeReferenceExpression"/>.</exception>
        public CSharpRelationalExpression(ICSharpRelationalExpression leftSide, CSharpRelationalOperation operation, ICSharpShiftExpression rightSide)
            : base(leftSide, rightSide)
        {
            if (rightSide == null)
            {
                throw new ArgumentNullException("rightSide");
            }
            if (leftSide == null && operation != CSharpRelationalOperation.Term)
            {
                throw new ArgumentNullException("leftSide", "Only nullable on term pass-throughs.");
            }
            this.operation = operation;
            switch (operation)
            {
            case CSharpRelationalOperation.LessThan:
            case CSharpRelationalOperation.LessThanOrEqualTo:
            case CSharpRelationalOperation.GreaterThan:
            case CSharpRelationalOperation.GreaterThanOrEqualTo:
            {
                IExpression detached = rightSide.Detach();
                if (detached is ITypeReferenceExpression)
                {
                    throw ThrowHelper.ObtainArgumentException(ArgumentWithException.rightSide, ExceptionMessageId.RelationalInvalidOnExpression);
                }
                break;
            }

            case CSharpRelationalOperation.TypeCheck:
            case CSharpRelationalOperation.TypeCastOrNull:
            {
                IExpression detached = rightSide.Detach();
                if (!(detached is ITypeReferenceExpression))
                {
                    throw ThrowHelper.ObtainArgumentException(ArgumentWithException.rightSide, ExceptionMessageId.TypeRelationalCheckRequiresType, ThrowHelper.GetArgumentName(ArgumentWithException.rightSide));
                }
                ITypeReferenceExpression itre = ((ITypeReferenceExpression)(detached));
                if (itre.ReferenceType == null)
                {
                    throw ThrowHelper.ObtainArgumentException(ArgumentWithException.rightSide, ExceptionMessageId.TypeRelationalTypeCannotBeNull);
                }
                if ((!(itre.ReferenceType is IReferenceType)) && (operation == CSharpRelationalOperation.TypeCastOrNull))
                {
                    throw ThrowHelper.ObtainArgumentException(ArgumentWithException.rightSide, ExceptionMessageId.TypeRelationalOrNullCastMustBeReference);
                }
                break;
            }

            case CSharpRelationalOperation.Term:
                if (leftSide != null)
                {
                    throw ThrowHelper.ObtainArgumentException(ArgumentWithException.operation, ExceptionMessageId.CannotTermBinaryOperation);
                }
                break;

            default:
                break;
            }
        }
Пример #2
0
 private static void WriteTypeReference(LanguageWriter w, ITypeReferenceExpression exp)
 {
     // if(exp.Type.Name=="UnmanagedType")return; // ←何故 UnmanagedType を略すのか不明
     if (exp.Type.Name == "<Module>")
     {
         return;
     }
     new TypeRef(exp.Type).WriteName(w);
 }
 public override bool Visit(ITypeReferenceExpression expression, object context)
 {
     _stack.Push(expression);
     try
     {
         return(base.Visit(expression, context));
     }
     finally
     {
         _stack.Pop();
     }
 }
Пример #4
0
        private bool ExtendsTheCallerType(IMethodElement method, ITypeElement callerType, Expression qualifier)
        {
            if (method == null || callerType == null)
            {
                return(false);
            }


            if (method.Parameters.Count == 0)
            {
                return(false);
            }
            ISourceTreeResolver  resolver  = ParserServices.SourceTreeResolver;
            ExpressionCollection arguments = new ExpressionCollection();

            arguments.Add(qualifier);
            method = GenericElementActivator.ActivateMemberIfNeeded(resolver, method, arguments, null, ArgumentsHelper.ResolveArgumentTypes(resolver, arguments)) as IMethodElement;

            if (method == null)
            {
                return(false);
            }

            IParameterElement extensionParam = method.Parameters[0] as IParameterElement;

            if (extensionParam == null)
            {
                return(false);
            }


            ITypeReferenceExpression typeRef = extensionParam.Type;

            if (typeRef == null)
            {
                return(false);
            }
            ITypeElement type = typeRef.GetDeclaration() as ITypeElement;

            if (type == null)
            {
                return(false);
            }
            IArrayTypeElement arrayType = callerType as IArrayTypeElement;

            //if (arrayType != null)
            //{
            //  return true;
            //}
            //else
            return(ArgumentsHelper.HasParamConversion(resolver, extensionParam, callerType, qualifier, TypeConversionMode.ImplicitConversion));
        }
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            ITypeReferenceExpression expression = obj as ITypeReferenceExpression;

            if (expression == null)
            {
                return(false);
            }

            return(this.Type.Equals(expression.Type));
        }
        } // IsElementOfType(DeclaredTypeElement, type)

        /// <summary>
        /// Is element of type
        /// </summary>
        public bool IsElementOfType(ITypeReferenceExpression declaredTypeExpression, string type)
        {
            try
            {
                if (declaredTypeExpression == null)
                {
                    return(false);
                }
                if (_NewSourceTreeResolver == null)
                {
                    _NewSourceTreeResolver = new SourceTreeResolver();
                }
                ITypeElement DeclaredTypeElement = _NewSourceTreeResolver.ResolveExpression(declaredTypeExpression) as ITypeElement;
                return(IsElementOfType(DeclaredTypeElement, type));
            } // try
            catch (Exception ex)
            {
                Trace.WriteLine("Exception in IsElementOfType Function: " + ex.Message);
            }
            return(false);
        } // IsElementOfType(declaredTypeExpression, type)
Пример #7
0
        //============================================================
        //	初期化
        //============================================================
        public AttributeCollection(LanguageWriter writer, ICustomAttributeProvider provider, IType type)
        {
            this.writer   = writer;
            this.provider = provider;
            this.type     = type;

            // 属性の対象
            if (provider is IAssembly)
            {
                attr_class    = "assembly";
                isAsmOrModule = true;
            }
            else if (provider is IModule)
            {
                attr_class    = "module";
                isAsmOrModule = true;
            }
            else if (provider is IMethodReturnType)
            {
                attr_class = "returnvalue";
            }

            // 個々の属性に対して走査
            foreach (ICustomAttribute attr in provider.Attributes)
            {
                if (attr == null)
                {
                    continue;
                }

                string attrname = GetCustomAttributeName(attr);
                switch (attrname)
                {
                case "ParamArray":
                case "System::ParamArray":
                    containsParams = true;
                    continue;

                case "MarshalAs":
                case "System::Runtime::InteropServices::MarshalAs":
                    IExpressionCollection arguments = attr.Arguments;
                    if (arguments == null)
                    {
                        break;
                    }
                    IFieldReferenceExpression exp_fld = arguments[0] as IFieldReferenceExpression;
                    if (exp_fld == null)
                    {
                        break;
                    }
                    ITypeReferenceExpression target = exp_fld.Target as ITypeReferenceExpression;
                    if (target == null || target.Type.Name != "UnmanagedType")
                    {
                        break;
                    }
                    IFieldReference field = exp_fld.Field;
                    if (field.Name == "U1")
                    {
                        if (LanguageWriter.Type(type, "System", "Boolean"))
                        {
                            continue;
                        }
                    }
                    else if (field.Name == "U2" && LanguageWriter.Type(type, "System", "Char"))
                    {
                        continue;
                    }
                    break;
                }

                attrs.Add(new AttrPair(attrname, attr));
            }

            // 名前空間順に並び替え
            attrs.Sort(delegate(AttrPair l, AttrPair r){
                string l_name = ((ITypeReference)l.Value.Constructor.DeclaringType).Namespace;
                string r_name = ((ITypeReference)r.Value.Constructor.DeclaringType).Namespace;
                return(l_name.CompareTo(r_name));
            });
        }
Пример #8
0
 public virtual void VisitTypeReferenceExpression(ITypeReferenceExpression value)
 {
     VisitType(value.Type);
 }
Пример #9
0
 public object Evaluate(IExpression expr)
 {
     if (expr is IObjectCreateExpression)
     {
         return(Evaluate((IObjectCreateExpression)expr));
     }
     else if (expr is ILiteralExpression)
     {
         return(((ILiteralExpression)expr).Value);
     }
     else if (expr is ICastExpression)
     {
         return(Evaluate(((ICastExpression)expr).Expression));
     }
     else if (expr is ICheckedExpression)
     {
         return(Evaluate(((ICheckedExpression)expr).Expression));
     }
     else if (expr is IBinaryExpression)
     {
         IBinaryExpression ibe   = (IBinaryExpression)expr;
         object            left  = Evaluate(ibe.Left);
         object            right = Evaluate(ibe.Right);
         Type type = left.GetType();
         return(Microsoft.ML.Probabilistic.Compiler.Reflection.Invoker.InvokeStatic(type, binaryOperatorNames[(int)ibe.Operator], left, right));
     }
     else if (expr is IUnaryExpression)
     {
         IUnaryExpression iue    = (IUnaryExpression)expr;
         object           target = Evaluate(iue.Expression);
         Type             type   = target.GetType();
         return(Microsoft.ML.Probabilistic.Compiler.Reflection.Invoker.InvokeStatic(type, unaryOperatorNames[(int)iue.Operator], target));
     }
     else if (expr is IMethodInvokeExpression)
     {
         IMethodInvokeExpression imie = (IMethodInvokeExpression)expr;
         object[] args = EvaluateAll(imie.Arguments);
         return(Invoke(imie.Method, args));
     }
     else if (expr is IArrayCreateExpression)
     {
         IArrayCreateExpression iace = (IArrayCreateExpression)expr;
         Type  t    = Builder.ToType(iace.Type);
         int[] lens = new int[iace.Dimensions.Count];
         for (int i = 0; i < lens.Length; i++)
         {
             lens[i] = (int)Evaluate(iace.Dimensions[i]);
         }
         // TODO: evaluate initializer
         if (iace.Initializer != null)
         {
             throw new NotImplementedException("IArrayCreateExpression has an initializer block");
         }
         return(Array.CreateInstance(t, lens));
     }
     else if (expr is IFieldReferenceExpression)
     {
         IFieldReferenceExpression ifre = (IFieldReferenceExpression)expr;
         if (ifre.Target is ITypeReferenceExpression)
         {
             ITypeReferenceExpression itre = (ITypeReferenceExpression)ifre.Target;
             Type      type = Builder.ToType(itre.Type);
             FieldInfo info = type.GetField(ifre.Field.Name);
             return(info.GetValue(null));
         }
         else
         {
             object    target = Evaluate(ifre.Target);
             FieldInfo info   = target.GetType().GetField(ifre.Field.Name);
             return(info.GetValue(target));
         }
     }
     else
     {
         throw new InferCompilerException("Could not evaluate: " + expr);
     }
 }
Пример #10
0
 public virtual void VisitTypeReferenceExpression(ITypeReferenceExpression value)
 {
     this.VisitType(value.Type);
 }
Пример #11
0
 public abstract TransformationImpact CalculateRefactorImpact(ITypeReferenceExpression expression);
Пример #12
0
 public abstract void Translate(ITypeReferenceExpression expression);
 private void WriteTypeReferenceExpression(ITypeReferenceExpression expression, IFormatter formatter)
 {
     this.WriteTypeReference(expression.Type, formatter);
 }
Пример #14
0
 public TransformationKind Visit(ITypeReferenceExpression expression, ITransformationContext context)
 {
     return(TransformationKind.Investigate);
 }
Пример #15
0
 public abstract void TranslateExpression(ITypeReferenceExpression typeRefExpression);
Пример #16
0
 public TestLinkerResult Visit(ITypeReferenceExpression expression, ICompilationContext context)
 {
     throw new NotImplementedException();
 }
Пример #17
0
 TransformationImpact IExpressionVisitor <TransformationImpact> .Visit(ITypeReferenceExpression expression)
 {
     return(CalculateRefactorImpact(expression));
 }
Пример #18
0
            //===========================================================
            //		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
            }
Пример #19
0
 void IExpressionVisitor.Visit(ITypeReferenceExpression expression)
 {
     this.Translate(expression);
 }
Пример #20
0
 public override void TranslateExpression(ITypeReferenceExpression typeRefExpression)
 {
     this.Provider.GenerateCodeFromExpression(typeRefExpression.GenerateCodeDom(this.Options), base.Target, this.Options.Options);
 }
Пример #21
0
 public abstract IExpression Transform(ITypeReferenceExpression expression);
        } // IsElementOfType(DeclaredTypeElement, type)

        /// <summary>
        /// Is element of type
        /// </summary>
        public bool IsElementOfType(ITypeReferenceExpression declaredTypeExpression, string type)
        {
            try
            {
                if (declaredTypeExpression == null)
                    return false;
                if (_NewSourceTreeResolver == null)
                    _NewSourceTreeResolver = new SourceTreeResolver();
                ITypeElement DeclaredTypeElement = _NewSourceTreeResolver.ResolveExpression(declaredTypeExpression) as ITypeElement;
                return IsElementOfType(DeclaredTypeElement, type);
            } // try
            catch (Exception ex)
            {
                Trace.WriteLine("Exception in IsElementOfType Function: " + ex.Message);
            }
            return false;
        } // IsElementOfType(declaredTypeExpression, type)
Пример #23
0
 public virtual void VisitTypeReferenceExpression(ITypeReferenceExpression e)
 {
 }
 public virtual IExpression TransformTypeReferenceExpression(ITypeReferenceExpression value)
 {
     return value;
 }