protected virtual void VisitNode(ClassDcl node) { // Create a type descriptor for the class // Put a new symbol table into the descriptor // Create a new attributes structure // Put the descriptor in the attributes structure // Put the class name and attributes structure in the symbol table. // ---------- // Configure the descriptor // Create a symbol table to hodl the names declared within the class // Create an attributes structure for the class // Enter class name into current symbol table // Open scope in the symbol table // Accept the dcl visitor for fields and methods Console.WriteLine("Visiting class"); }
protected void VisitNode(ClassDcl node) { // Write class header StringBuilder sb = new StringBuilder(); Byte[] info; ClassTypeDescriptor CTD = node.attrRef.typeInfo; string modList = ""; foreach (string modifier in CTD.Modifiers) { modList += modifier + " "; } modList = modList.ToLower(); string className = node.Name; sb.AppendLine(String.Format(".class {0}auto ansi beforefieldinit {1} \nextends [mscorlib]System.Object \n", modList, className)); info = new UTF8Encoding(true).GetBytes(sb.ToString()); TCCLParser.currentFileStream.Write(info, 0, info.Length); // Write method header /* ------------------------ Visit All Fields -------------------------*/ // Create a list of ClassBody children (should only be one) Utilities.VisitSpecificChild(node, typeof(ClassBody), this); }
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/ protected override void VisitNode(ClassDcl node) { // Create a type descriptor for the class ClassTypeDescriptor typeRef = new ClassTypeDescriptor(); // Put a new symbol table into the descriptor typeRef.ClassSymbolTable = new SymbolTable(); // Create a new attributes structure Attributes attr = new Attributes("classDcl"); // Put the descriptor in the attributes structure attr.typeInfo = typeRef; // Put the class name and attributes structure in the symbol table. String name = Utilities.FilterOutKeywords(node.Name); // Record our name globally currentClassName = Utilities.FilterOutKeywords(node.Name); currentSymbolTable.enter(name, attr); // Decorate AST with attrRef node.attrRef = attr; /* -----------------------------*/ // Configure the descriptor // Create a list of all modifier children List <Modifier> modifierChildren = Utilities.GetChildren(node, typeof(Modifier)).Cast <Modifier>().ToList(); // Process modifier children List <String> listOfModiifers = new List <String>(); foreach (Modifier m in modifierChildren) { listOfModiifers.Add(m.Name); } // Add the list of modifiers to the Type Descriptor typeRef.Modifiers = listOfModiifers; // Switch current symbol table to class's //currentSymbolTable = typeRef.ClassSymbolTable; currentSymbolTable.incrNestLevel(); /* ------------------------ Visit All Fields -------------------------*/ // Create a list of ClassBody children (should only be one) List <ClassBody> classBodyChildren = Utilities.GetChildren(node, typeof(ClassBody)).Cast <ClassBody>().ToList(); foreach (ClassBody c in classBodyChildren) { this.VisitNode(c); } currentSymbolTable.decrNestLevel(); }