public InterField AddField(string name, TypeName type, string access, List <string> keywords) { InterField field = new InterField(name, type, access, keywords, new InterUserType(CurrentType)); _tables.Peek().AddSymbol(field.Symbol); CurrentType.AddField(field); return(field); }
public FieldSymbol(InterField field) : base() { _field = field; _owningType = field.Owner; Field = new InterFieldWrapper(field); ID = field.Name; _initFromInterField = true; }
public void CompilePropertyDecleration(SyntaxTreeNode node) { var decHeader = node[0]; string access = decHeader[0].ValueString; var type = TypeNameFromNode(decHeader[2]); List <string> keywords = new List <string>(); foreach (var c in decHeader[1].Children) { keywords.Add(c.ValueString); } string name = node[1].ValueString; InterMethod getMethod = null, setMethod = null; bool auto = false; InterProperty property = builder.AddProperty(name, type, access, keywords); InterField backingField = null; foreach (var dec in node[2].Children) { if (!auto && dec.Op == "AutoAccessorDec") { auto = true; backingField = builder.AddField(name + "__backingField", type, access, keywords); } bool get = dec[0].ValueString == "get"; List <string> funcKeywords = new List <string>(keywords); funcKeywords.Add(dec[1].ValueString); PushNewTable(); if (get) { getMethod = builder.AddMethod("get_" + name, type, new ArgumentSymbol[] { }, funcKeywords); } else { var arg = new ArgumentSymbol("value", type, 0); setMethod = builder.AddMethod("set_" + name, new BasicTypeName("void"), new ArgumentSymbol[] { arg }, funcKeywords); } if (!auto) { CompileNode(dec[2]); } else { if (get) { var resolver = new LateReferenceResolver(builder.CurrentNamespaceContext, backingField.Name); resolver.SetOwner(builder.CurrentMethod); builder.AddInstruction(new InterRet(new InterOpValue(resolver))); } else { builder.AddInstruction(new InterCopy(backingField.Symbol, GetFirst("value"))); } } Tables.Pop(); } if (auto && node[3].Children.Length > 0) { backingField.Initializer = ToIntermediateExpression(node[3][0]); } if (getMethod != null) { property.SetGet(getMethod); } if (setMethod != null) { property.SetSet(setMethod); } }