using System.Reflection.Emit; // Z# Code Item. // An item stores the attributes of an operand during code generation. public class Item { public enum Kind { Const, Arg, Local, Static, Field, Stack, Elem, Meth, Cond } public Kind kind; // Const, Local, Static, Stack, Field, Elem, Method, Cond public Struct type; // item type public int val; // Const: value public int adr; // Arg, Local: offset public int relop; // Cond: token code of relational operator public Symbol sym; // Field, Meth: node from symbol table public Label tLabel, fLabel; // Cond: true jumps, false jumps public Item (Symbol sym) { type = sym.type; this.sym = sym; switch (sym.kind) { case Symbol.Kind.Const: kind = Kind.Const; val = sym.val; break; case Symbol.Kind.Arg: kind = Kind.Arg; adr = sym.adr; break; case Symbol.Kind.Local: kind = Kind.Local; adr = sym.adr; break; case Symbol.Kind.Global: kind = Kind.Static; break; case Symbol.Kind.Field: kind = Kind.Field; break; case Symbol.Kind.Meth: kind = Kind.Meth; break; default: Parser.Error("Cannot create code item for this kind of symbol table object"); break; } } // special constructor for Const Items public Item (int val) { kind = Kind.Const; type = Tab.intType; this.val = val; } // special constructor for Cond Items public Item (int relop, Struct type) { this.kind = Kind.Cond; this.type = type; this.relop = relop; tLabel = Code.il.DefineLabel(); fLabel = Code.il.DefineLabel(); } // special constructor for Stack Items public Item (Struct type) { kind = Kind.Stack; this.type = type; } }