Example #1
0
 public void AddType(LuatType type)
 {
     if (false == m_types.Contains(type))
     {
         m_types.Add(type);
     }
 }
Example #2
0
 public LuatLiteral(LuatType type)
     : base(null)
 {
     m_type = type;
 }
Example #3
0
 public LuatVariable(LuatValue parent, LuatType type, LuatVariableFlags flags)
     : base(parent)
 {
     m_flags = flags;
     m_type = type;
 }
Example #4
0
        /// <summary>
        /// Attempts to resolve (or infer) the variable type
        /// </summary>
        /// <param name="variable"></param>
        /// <returns>true if the type was resolved or false if the type could not be resolved</returns>
        private bool ResolveVariableType(LuatVariable variable)
        {
            LuatType type = variable.Type;

            foreach (LuatValue.IReference assignment in variable.Assignments)
            {
                if (null == assignment.Value)
                {
                    return(false);
                }

                LuatType rhsType = assignment.Value.Type;

                if (rhsType is LuatTypeUnknown)
                {
                    // Being assigned an unknown results in an unknown
                    return(false);
                }

                if (type is LuatTypeUnknown || type is LuatTypeNil)
                {
                    type = rhsType;
                    continue;
                }

                if (rhsType is LuatTypeNil)
                {
                    continue;
                }

                if (type.Equals(rhsType))
                {
                    continue;
                }

                if (variable.IsFixedType)
                {
                    assignment.AddWarning(WarningType.FixedType, string.Format("Type is fixed to {0}", type));
                    continue;
                }

                // Mixed types.
                var mixed = type as LuatTypeMixed;
                if (null == mixed)
                {
                    mixed = new LuatTypeMixed();
                    mixed.AddType(type);
                    type = mixed;
                }

                mixed.AddType(rhsType);
            }

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

            variable.Type = type;

            // Propagate resolving of variable types through expressions
            foreach (LuatValue.IReference reference in variable.References)
            {
                reference.OnTypeInvalidated();
            }

            return(true);
        }
Example #5
0
 public void AddType(LuatType type)
 {
     if (false == m_types.Contains(type))
     {
         m_types.Add(type);
     }
 }
Example #6
0
 public LuatVariable(LuatValue parent, LuatType type, LuatVariableFlags flags)
     : base(parent)
 {
     m_flags = flags;
     m_type  = type;
 }
Example #7
0
 public LuatLiteral(LuatType type)
     : base(null)
 {
     m_type = type;
 }