public override object VisitEnumTypeDefDecl(PParser.EnumTypeDefDeclContext context) { // ENUM name=iden PEnum pEnum = (PEnum)nodesToDeclarations.Get(context); // LBRACE enumElemList RBRACE if (context.enumElemList() is PParser.EnumElemListContext elemList) { EnumElem[] elems = (EnumElem[])Visit(elemList); for (int i = 0; i < elems.Length; i++) { EnumElem elem = elems[i]; elem.Value = i; pEnum.AddElement(elem); } } // | LBRACE numberedEnumElemList RBRACE else if (context.numberedEnumElemList() is PParser.NumberedEnumElemListContext numberedElemList) { EnumElem[] numberedElems = (EnumElem[])Visit(numberedElemList); foreach (EnumElem elem in numberedElems) { pEnum.AddElement(elem); } } else { Debug.Fail("grammar requires enum declarations to have element lists"); } return(pEnum); }
public override object VisitNumberedEnumElem(PParser.NumberedEnumElemContext context) { string symbolName = context.name.GetText(); EnumElem elem = CurrentScope.Put(symbolName, context); nodesToDeclarations.Put(context, elem); return(null); }
public EnumElem Put(string name, PParser.NumberedEnumElemContext tree) { EnumElem enumElem = new EnumElem(name, tree); CheckConflicts(enumElem, Namespace(enumElems), Namespace(events)); enumElems.Add(name, enumElem); return(enumElem); }
public override object VisitNumberedEnumElem(PParser.NumberedEnumElemContext context) { // name=iden ASSIGN value=IntLiteral EnumElem elem = (EnumElem)nodesToDeclarations.Get(context); elem.Value = int.Parse(context.value.Text); return(elem); }
public bool Lookup(string name, out EnumElem tree) { Scope current = this; while (current != null) { if (current.Get(name, out tree)) { return(true); } current = current.Parent; } tree = null; return(false); }
public string GetEnumElementName(EnumElem elem) { return(elem.Name); }
public bool Get(string name, out EnumElem tree) { return(enumElems.TryGetValue(name, out tree)); }
public EnumElemRefExpr(ParserRuleContext sourceLocation, EnumElem enumElem) { SourceLocation = sourceLocation; EnumElem = enumElem; Type = new EnumType(EnumElem.ParentEnum); }