示例#1
0
 public void AddType(LuatType type)
 {
     if (false == m_types.Contains(type))
     {
         m_types.Add(type);
     }
 }
示例#2
0
 public LuatLiteral(LuatType type)
     : base(null)
 {
     m_type = type;
 }
示例#3
0
 public LuatVariable(LuatValue parent, LuatType type, LuatVariableFlags flags)
     : base(parent)
 {
     m_flags = flags;
     m_type = type;
 }
示例#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);
        }
示例#5
0
文件: LuatType.cs 项目: arsaccol/SLED
 public void AddType(LuatType type)
 {
     if (false == m_types.Contains(type))
     {
         m_types.Add(type);
     }
 }
示例#6
0
 public LuatVariable(LuatValue parent, LuatType type, LuatVariableFlags flags)
     : base(parent)
 {
     m_flags = flags;
     m_type  = type;
 }
示例#7
0
 public LuatLiteral(LuatType type)
     : base(null)
 {
     m_type = type;
 }