private void VisitNode(MethodDeclaration node) { // catch errors prior to entering method declaration ErrorDescriptor err = node.TypeDescriptor as ErrorDescriptor; if (err != null) { PrintError(err); return; } _localVariables.OpenScope(); MethodTypeDescriptor desc = node.TypeDescriptor as MethodTypeDescriptor; if (desc != null) { AbstractNode modifiers = node.Child; AbstractNode typeSpecifier = modifiers.Sib; AbstractNode methodDeclarator = typeSpecifier.Sib; AbstractNode methodBody = methodDeclarator.Sib; AbstractNode methodDeclaratorName = methodDeclarator.Child; AbstractNode parameterList = methodDeclaratorName.Sib; // may be null string name = ((Identifier)methodDeclaratorName).ID; if (!desc.Modifiers.Contains(ModifiersEnums.STATIC) /*&& * name.ToLower().Equals("main")*/) { desc.Modifiers.Add(ModifiersEnums.STATIC); } string mods = String.Join(" ", desc.Modifiers).ToLower(); string typeSpec = GetIlType(desc.ReturnType, typeSpecifier); string argList = GetIlTypeParams(desc.Signature.ParameterTypes); string begin = name.ToLower().Equals("main") ? "\n{\n.entrypoint\n.maxstack 42\n" : "\n{\n.maxstack 42"; string end = "ret\n}"; File.WriteLine($".method {mods} {typeSpec} {name}" + $"({argList}) {begin}"); methodBody.Accept(this); File.WriteLine(end); _localVariables.CloseScope(); } }