private static UnionType GenerateAllUnionTypes()
        {
            UnionType unions = new UnionType();

            unions.AddType(CharType.Instance);
            unions.AddType(IntType.Instance);
            unions.AddType(DoubleType.Instance);
            return(unions);
        }
        protected override UnionType GenerateAllUnionTypes()
        {
            UnionType unions = new UnionType();

            if (!(node.FirstOperand.ExpressionType is NullType) && !(node.SecondOperand.ExpressionType is NullType))
            {
                unions.AddType(IntType.Instance);
                unions.AddType(DoubleType.Instance);
                unions.AddType(CharType.Instance);
            }
            return(unions);
        }
        protected override UnionType GenerateAllUnionTypes()
        {
            UnionType unions = new UnionType();

            unions.AddType(IntType.Instance);
            unions.AddType(DoubleType.Instance);
            unions.AddType(CharType.Instance);
            if (((ArithmeticExpression)node).Operator == ArithmeticOperator.Plus)
            {
                unions.AddType(StringType.Instance);
            }
            return(unions);
        }
        protected override UnionType GenerateAllUnionTypes()
        {
            UnionType unions = new UnionType();

            unions.AddType(IntType.Instance);
            return(unions);
        }
        private UnionType GenerateAllUnionTypes()
        {
            UnionType unions = new UnionType();

            if (node.Operator == UnaryOperator.Plus || node.Operator == UnaryOperator.Minus || node.Operator == UnaryOperator.BitwiseNot)
            {
                unions.AddType(CharType.Instance);
                unions.AddType(IntType.Instance);
                unions.AddType(DoubleType.Instance);
            }
            else if (node.Operator == UnaryOperator.Not)
            {
                unions.AddType(BoolType.Instance);
            }
            return(unions);
        }
Esempio n. 6
0
        private static TypeExpression getFieldType(TypeExpression type, string fieldName)
        {
            ClassType classType = TypeExpression.As <ClassType>(type);

            if (classType != null)
            {
                if (!classType.Fields.ContainsKey(fieldName))
                {
                    return(null);
                }
                TypeExpression field     = classType.Fields[fieldName].Type;
                FieldType      fieldType = TypeExpression.As <FieldType>(field);
                if (fieldType == null)
                {
                    return(field);
                }
                return(fieldType.FieldTypeExpression);
            }
            UnionType unionType = TypeExpression.As <UnionType>(type);

            if (unionType != null)
            {
                UnionType newUnionType = new UnionType();
                foreach (TypeExpression typeInUnion in unionType.TypeSet)
                {
                    TypeExpression newType = SSAHelper.getFieldType(typeInUnion, fieldName);
                    newUnionType.AddType(newType);
                }
                return(newUnionType);
            }
            return(null);
        }
Esempio n. 7
0
        private TypeExpression InternalPromotion(UnionType from, object arg)
        {
            if (from.IsFreshVariable() && this.methodAnalyzed != null)
            {
                // * A constraint is added to the method analyzed
                PromotionConstraint constraint = new PromotionConstraint(from, this.to, this.op, this.location);
                this.methodAnalyzed.AddConstraint(constraint);
                return(this.to);
            }
            // * Static Behaviour: All the types in typeset must promote
            // * Dynamic Behaviour: One of the types in typeset must promote
            int       aux = 0;
            UnionType dynamicUnionType = new UnionType();

            dynamicUnionType.IsDynamic = true;
            foreach (TypeExpression subType in from.TypeSet)
            {
                if (from.IsDynamic)
                {
                    // * Dynamic
                    if (subType.IsFreshVariable())
                    {
                        dynamicUnionType.AddType(subType);
                    }
                    else
                    {
                        aux = (int)subType.AcceptOperation(new PromotionLevelOperation(this.to), arg);
                        if (aux != -1)
                        {
                            return(this.to);
                        }
                    }
                }
                else     // * !from.IsDynamic, so it is static
                {
                    aux = (int)subType.AcceptOperation(new PromotionLevelOperation(this.to), arg);
                    if (aux == -1)
                    {
                        return((TypeExpression)ReportError(from));
                    }
                }
            }
            if (dynamicUnionType.Count != 0)    // * If the union type is dynamic and no type in the type set promotes, then we generate a constraint with one promotion grouping the fresh types in the type set
            {
                PromotionConstraint constraint = new PromotionConstraint(dynamicUnionType, this.to, this.op, this.location);
                this.methodAnalyzed.AddConstraint(constraint);
                return(this.to);
            }
            if (from.IsDynamic && aux == -1)
            {
                // * No promotion at all
                return((TypeExpression)ReportError(from));
            }
            return(this.to);
        }
Esempio n. 8
0
 public override object Exec(TypeExpression typeExpression, object arg)
 {
     if (typeExpression is UnionType)
     {
         this.Exec(typeExpression as UnionType, arg);
     }
     else if (typeExpression is TypeVariable)
     {
         this.Exec(typeExpression as TypeVariable, arg);
     }
     else if (typeExpression is PropertyType)
     {
         this.Exec(((PropertyType)typeExpression).PropertyTypeExpression, arg);
     }
     else if (typeExpression is FieldType)
     {
         FieldType fieldType = ((FieldType)typeExpression);
         if (fieldType.FieldTypeExpression is TypeVariable && ((TypeVariable)fieldType.FieldTypeExpression).Substitution != null && ((TypeVariable)fieldType.FieldTypeExpression).Substitution.IsValueType())
         {
             UnionType union = new UnionType();
             union.AddType(((TypeVariable)((FieldType)typeExpression).FieldTypeExpression).Substitution);
             this.Exec(union, arg);
         }
         else
         {
             this.Exec(((FieldType)typeExpression).FieldTypeExpression, arg);
         }
     }
     else if (IsValueType(typeExpression) || TypeExpression.Is <StringType>(typeExpression))
     {
         GenerateRightOperand(typeExpression, this.node.SecondOperand.ILTypeExpression);
     }
     else if (typeExpression is NullType)
     {
         this.codeGenerator.ldnull(this.indent);
         GenerateRightOperand(typeExpression, this.node.SecondOperand.ILTypeExpression);
     }
     else if (typeExpression is UserType)
     {
         GenerateRightOperand(typeExpression, this.node.SecondOperand.ILTypeExpression);
     }
     return(null);
 }
Esempio n. 9
0
 private void GenerateRightOperand(TypeExpression teLeft, TypeExpression teRight)
 {
     if (teRight is UnionType)
     {
         this.GenerateRightOperand(teLeft, teRight as UnionType);
     }
     else if (teRight is TypeVariable)
     {
         this.GenerateRightOperand(teLeft, teRight as TypeVariable);
     }
     else if (teRight is PropertyType)
     {
         GenerateRightOperand(teLeft, ((PropertyType)teRight).PropertyTypeExpression);
     }
     else if (teRight is FieldType)
     {
         FieldType fieldType = ((FieldType)teRight);
         if (fieldType.FieldTypeExpression is TypeVariable && ((TypeVariable)fieldType.FieldTypeExpression).Substitution != null && ((TypeVariable)fieldType.FieldTypeExpression).Substitution.IsValueType())
         {
             UnionType union = new UnionType();
             union.AddType(((TypeVariable)((FieldType)teRight).FieldTypeExpression).Substitution);
             GenerateRightOperand(teLeft, union);
         }
         else
         {
             GenerateRightOperand(teLeft, ((FieldType)teRight).FieldTypeExpression);
         }
     }
     else if (IsValueType(teRight) || TypeExpression.Is <StringType>(teRight))
     {
         if (IsInternallyAnObject(node.FirstOperand))
         {
             if (!(teLeft is StringType) && IsValueType(teRight))
             {
                 this.codeGenerator.UnboxAny(indent, teLeft);
             }
         }
         else
         {
             if (!CheckUnBox(teLeft, teRight))
             {
                 CheckBox(teLeft, teRight);
             }
         }
         LoadSecondOperand();
         if (IsInternallyAnObject(node.SecondOperand))
         {
             if (!(teRight is StringType) && IsValueType(teLeft))
             {
                 this.codeGenerator.UnboxAny(indent, teRight);
             }
         }
         else
         {
             if (!CheckUnBox(teRight, teLeft))
             {
                 CheckBox(teRight, teLeft);
             }
         }
         GenerateOperator(node, MajorType(teLeft, teRight));
     }
     else if (teRight is NullType)
     {
         this.codeGenerator.ldnull(this.indent);
         GenerateOperator(node, MajorType(teLeft, teRight));
     }
 }