public void SetVariableAssigned (VariableInfo variable, bool generatedAssignment = false) { variable.SetAssigned (DefiniteAssignment, generatedAssignment); }
public void SetStructFieldAssigned (VariableInfo variable, string name) { variable.SetStructFieldAssigned (DefiniteAssignment, name); }
public bool IsDefinitelyAssigned (VariableInfo variable) { return variable.IsAssigned (DefiniteAssignment); }
public bool IsStructFieldDefinitelyAssigned (VariableInfo variable, string name) { return variable.IsStructFieldAssigned (DefiniteAssignment, name); }
public static VariableInfo Create (BlockContext bc, Parameter parameter) { var info = new VariableInfo (parameter.Name, parameter.Type, bc.AssignmentInfoOffset, bc) { IsParameter = true }; bc.AssignmentInfoOffset += info.Length; return info; }
public static VariableInfo Create (BlockContext bc, LocalVariable variable) { var info = new VariableInfo (variable.Name, variable.Type, bc.AssignmentInfoOffset, bc); bc.AssignmentInfoOffset += info.Length; return info; }
void Initialize () { TypeInfo[] sub_fields = TypeInfo.SubStructInfo; if (sub_fields != null) { sub_info = new VariableInfo [sub_fields.Length]; for (int i = 0; i < sub_fields.Length; i++) { if (sub_fields [i] != null) sub_info [i] = new VariableInfo (this, sub_fields [i]); } } else sub_info = new VariableInfo [0]; }
VariableInfo (VariableInfo parent, TypeInfo type) { this.Name = parent.Name; this.TypeInfo = type; this.Offset = parent.Offset + type.Offset; this.Length = type.TotalLength; this.IsParameter = parent.IsParameter; Initialize (); }
// <summary> // A struct's constructor must always assign all fields. // This method checks whether it actually does so. // </summary> public bool IsFullyInitialized (FlowAnalysisContext fc, VariableInfo vi, Location loc) { if (struct_info == null) return true; bool ok = true; for (int i = 0; i < struct_info.Count; i++) { var field = struct_info.Fields[i]; if (!fc.IsStructFieldDefinitelyAssigned (vi, field.Name)) { var bf = field.MemberDefinition as Property.BackingFieldDeclaration; if (bf != null) { if (bf.Initializer != null) continue; fc.Report.Error (843, loc, "An automatically implemented property `{0}' must be fully assigned before control leaves the constructor. Consider calling the default struct contructor from a constructor initializer", field.GetSignatureForError ()); ok = false; continue; } fc.Report.Error (171, loc, "Field `{0}' must be fully assigned before control leaves the constructor", field.GetSignatureForError ()); ok = false; } } return ok; }