public void AddType(LuatType type) { if (false == m_types.Contains(type)) { m_types.Add(type); } }
public LuatLiteral(LuatType type) : base(null) { m_type = type; }
public LuatVariable(LuatValue parent, LuatType type, LuatVariableFlags flags) : base(parent) { m_flags = flags; m_type = type; }
/// <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); }