using System; using System.Collections.Generic; using System.Linq; using System.Text; using Antlr.Runtime.Tree; using Antlr.Runtime; using Twiglet.CS2J.Translator.Utils; using Twiglet.CS2J.Translator.TypeRep; using Twiglet.CS2J.Translator; namespace Twiglet.CS2J.Translator.Transform { public class CommonWalker : TreeParser { public CS2JSettings Cfg { get; set; } public string Filename { get; set; } // AppEnv contains a summary of the environment within which we are translating, it maps fully qualified type names to their // translation templates (i.e. a description of their public features) public DirectoryHT AppEnv {get; set;} protected CommonWalker(ITreeNodeStream input, RecognizerSharedState state) : base(input, state) { } protected void Error(int line, String s) { Console.Error.WriteLine("{0}({1}) error: {2}", Filename, line, s); } protected void Error(String s) { Console.Error.WriteLine("{0} error: {1}", Filename, s); } protected void Warning(int line, String s) { if (Cfg.Warnings) Console.Out.WriteLine("{0}({1}) warning: {2}", Filename, line, s); } protected void Warning(String s) { if (Cfg.Warnings) Console.Out.WriteLine("{0} warning: {1}", Filename, s); } protected void WarningAssert(bool assertion, int line, String s) { if (Cfg.Warnings && !assertion) Console.Out.WriteLine("{0}({1}) failed assertion: {2}", Filename, line, s); } protected void WarningAssert(bool assertion, String s) { if (Cfg.Warnings && !assertion) Console.Out.WriteLine("{0} failed assertion: {1}", Filename, s); } protected void Debug(String s) { Debug(1, s); } protected void DebugDetail(string s) { Debug(5, s); } protected void Debug(int level, String s) { if (level <= Cfg.DebugLevel) { Console.Out.WriteLine(s); } } // distinguish classes with same name, but differing numbers of type arguments protected string mkTypeName (string name, List tyargs) { return name + (tyargs != null && tyargs.Count > 0 ? "'" + tyargs.Count.ToString() : ""); } protected string formatTyargs(List tyargs) { if (tyargs.Count == 0) { return ""; } StringBuilder buf = new StringBuilder(); buf.Append("<"); foreach (string t in tyargs) { buf.Append(t + ","); } buf.Remove(buf.Length-1,1); buf.Append(">"); return buf.ToString(); } } // Wraps a compilation unit with its imports search path public class CUnit { public CUnit(CommonTree inTree, List inSearchPath, List inAliasKeys, List inAliasValues) { Tree = inTree; SearchPath = inSearchPath; NameSpaceAliasKeys = inAliasKeys; NameSpaceAliasValues = inAliasValues; } public CommonTree Tree {get; set;} // namespaces in scope public List SearchPath {get; set;} // aliases for namespaces public List NameSpaceAliasKeys {get; set;} public List NameSpaceAliasValues {get; set;} } }