/// <summary> /// Sets the value associated with the named field /// </summary> /// <param name="name"></param> /// <param name="val"></param> public virtual void SetField(string name, HeronValue val) { HeronType t = Type; FieldDefn fi = t.GetField(name); fi.SetValue(this, val); }
static void ProcessFields(ParseNode x, ClassDefn defn) { Dictionary <string, Expression> initializers = new Dictionary <string, Expression>(); ParseNode fields = x.GetChild("fields"); if (fields != null) { foreach (ParseNode node in fields.Children) { FieldDefn fd = CreateField(node); fd.annotations = CreateAnnotations(node); defn.AddField(fd); ParseNode exprNode = node.GetChild("expr"); if (exprNode != null) { Expression expr = CreateExpr(exprNode); initializers.Add(fd.name, expr); } } } foreach (string s in initializers.Keys) { Assignment ass = new Assignment(new Name(s), initializers[s]); ExpressionStatement st = new ExpressionStatement(ass); defn.GetAutoConstructor().body.statements.Add(st); } }
public static FieldDefn CreateField(ParseNode x) { FieldDefn r = new FieldDefn(); r.name = x.GetChild("name").ToString(); r.type = CreateTypeRef(x.GetChild("typedecl")); if (x.HasChild("expr")) { r.expr = CreateExpr(x.GetChild("expr")); } return(r); }
/// <summary> /// Given a name returns the appropriate field (or method) /// </summary> /// <param name="name"></param> /// <returns></returns> public virtual HeronValue GetFieldOrMethod(string name) { HeronType t = Type; ExposedMethodValue m = t.GetMethod(name); if (m != null) { return(m.CreateBoundMethod(this)); } FieldDefn f = t.GetField(name); if (f != null) { return(f.GetValue(this)); } return(null); }
public void AddField(FieldDefn x) { fields.Add(x); }