javaccglobals.java

来自「java 编译器java复杂编译器,可以编译java文件的类库」· Java 代码 · 共 586 行 · 第 1/2 页

JAVA
586
字号
  }  /**   * Returns a Vector of names of the tools that have been used to generate   * the given file.   */  public static Vector getToolNames(String fileName) {     char[] buf = new char[256];     java.io.FileReader stream = null;     int read, total = 0;     try {       stream = new java.io.FileReader(fileName);       for (;;)          if ((read = stream.read(buf, total, buf.length - total)) != -1)          {             if ((total += read) == buf.length)                break;          }          else             break;       return makeToolNameVector(new String(buf, 0, total));    } catch(java.io.FileNotFoundException e1) {    } catch(java.io.IOException e2) {       if (total > 0)          return makeToolNameVector(new String(buf, 0, total));    }    finally {       try { stream.close(); }       catch (Exception e3) { }    }    return new Vector();  }  public static void storeOutputDirSpec(Object loc, String val) {    outputDirName = val;    outputDirNameLoc = loc;  }  public static void setOutputDir() {     if (outputDirName == null)        return;     File tmp = new File(outputDirName);     if (!tmp.exists()) {        if (outputDirNameLoc == null)           JavaCCErrors.warning("Output directory \"" + outputDirName + "\" does not exist. Creating the directory.");        else           JavaCCErrors.warning(outputDirNameLoc, "Output directory \"" + outputDirName + "\" does not exist. Creating the directory.");        if (!tmp.mkdir()) {           if (outputDirNameLoc == null)              JavaCCErrors.semantic_error("Cannot create the output directory : " + outputDirName);           else              JavaCCErrors.semantic_error(outputDirNameLoc, "Cannot create the output directory : " + outputDirName);           return;        }     }     if (!tmp.isDirectory()) {        if (outputDirNameLoc == null)           JavaCCErrors.semantic_error("\"" + outputDirName + " is not a valid output directory.");        else           JavaCCErrors.semantic_error(outputDirNameLoc, "\"" + outputDirName + " is not a valid output directory.");        return;     }     if (!tmp.canWrite()) {        if (outputDirNameLoc == null)           JavaCCErrors.semantic_error("Cannot write to the output output directory : \"" + outputDirName + "\"");        else           JavaCCErrors.semantic_error(outputDirNameLoc, "Cannot write to the output output directory : \"" + outputDirName + "\"");        return;     }     outputDir = tmp;  }  static public String staticOpt() {    if (Options.B("STATIC")) {      return "static ";    } else {      return "";    }  }  static public String add_escapes(String str) {    String retval = "";    char ch;    for (int i = 0; i < str.length(); i++) {      ch = str.charAt(i);      if (ch == '\b') {        retval += "\\b";      } else if (ch == '\t') {        retval += "\\t";      } else if (ch == '\n') {        retval += "\\n";      } else if (ch == '\f') {        retval += "\\f";      } else if (ch == '\r') {        retval += "\\r";      } else if (ch == '\"') {        retval += "\\\"";      } else if (ch == '\'') {        retval += "\\\'";      } else if (ch == '\\') {        retval += "\\\\";      } else if (ch < 0x20 || ch > 0x7e) {	String s = "0000" + Integer.toString(ch, 16);	retval += "\\u" + s.substring(s.length() - 4, s.length());      } else {        retval += ch;      }    }    return retval;  }  static public String addUnicodeEscapes(String str) {    String retval = "";    char ch;    for (int i = 0; i < str.length(); i++) {      ch = str.charAt(i);      if (ch < 0x20 || ch > 0x7e) {	String s = "0000" + Integer.toString(ch, 16);	retval += "\\u" + s.substring(s.length() - 4, s.length());      } else {        retval += ch;      }    }    return retval;  }  static protected int cline, ccol;  static protected void printTokenSetup(Token t) {    Token tt = t;    while (tt.specialToken != null) tt = tt.specialToken;    cline = tt.beginLine;    ccol = tt.beginColumn;  }  static protected void printTokenOnly(Token t, java.io.PrintWriter ostr) {    for (; cline < t.beginLine; cline++) {      ostr.println(""); ccol = 1;    }    for (; ccol < t.beginColumn; ccol++) {      ostr.print(" ");    }    if (t.kind == JavaCCParserConstants.STRING_LITERAL ||        t.kind == JavaCCParserConstants.CHARACTER_LITERAL)       ostr.print(addUnicodeEscapes(t.image));    else       ostr.print(t.image);    cline = t.endLine;    ccol = t.endColumn+1;    char last = t.image.charAt(t.image.length()-1);    if (last == '\n' || last == '\r') {      cline++; ccol = 1;    }  }  static protected void printToken(Token t, java.io.PrintWriter ostr) {    Token tt = t.specialToken;    if (tt != null) {      while (tt.specialToken != null) tt = tt.specialToken;      while (tt != null) {        printTokenOnly(tt, ostr);        tt = tt.next;      }    }    printTokenOnly(t, ostr);  }  static protected void printLeadingComments(Token t, java.io.PrintWriter ostr) {    if (t.specialToken == null) return;    Token tt = t.specialToken;    while (tt.specialToken != null) tt = tt.specialToken;    while (tt != null) {      printTokenOnly(tt, ostr);      tt = tt.next;    }    if (ccol != 1 && cline != t.beginLine) {      ostr.println("");      cline++; ccol = 1;    }  }  static protected void printTrailingComments(Token t, java.io.PrintWriter ostr) {    if (t.next == null) return;    printLeadingComments(t.next);  }  static protected String printTokenOnly(Token t) {    String retval = "";    for (; cline < t.beginLine; cline++) {      retval += "\n"; ccol = 1;    }    for (; ccol < t.beginColumn; ccol++) {      retval += " ";    }    if (t.kind == JavaCCParserConstants.STRING_LITERAL ||        t.kind == JavaCCParserConstants.CHARACTER_LITERAL)       retval += addUnicodeEscapes(t.image);    else       retval += t.image;    cline = t.endLine;    ccol = t.endColumn+1;    char last = t.image.charAt(t.image.length()-1);    if (last == '\n' || last == '\r') {      cline++; ccol = 1;    }    return retval;  }  static protected String printToken(Token t) {    String retval = "";    Token tt = t.specialToken;    if (tt != null) {      while (tt.specialToken != null) tt = tt.specialToken;      while (tt != null) {        retval += printTokenOnly(tt);        tt = tt.next;      }    }    retval += printTokenOnly(t);    return retval;  }  static protected String printLeadingComments(Token t) {    String retval = "";    if (t.specialToken == null) return retval;    Token tt = t.specialToken;    while (tt.specialToken != null) tt = tt.specialToken;    while (tt != null) {      retval += printTokenOnly(tt);      tt = tt.next;    }    if (ccol != 1 && cline != t.beginLine) {      retval += "\n";      cline++; ccol = 1;    }    return retval;  }  static protected String printTrailingComments(Token t) {    if (t.next == null) return "";    return printLeadingComments(t.next);  }   public static void reInit()   {      fileName = null;      origFileName = null;      outputDir = new File(System.getProperty("user.dir"));      outputDirName = null;      outputDirNameLoc = null;      jjtreeGenerated = false;      jjcovGenerated = false;      toolNames = null;      cu_name = null;      cu_to_insertion_point_1 = new java.util.Vector();      cu_to_insertion_point_2 = new java.util.Vector();      cu_from_insertion_point_2 = new java.util.Vector();      bnfproductions = new java.util.Vector();      production_table = new java.util.Hashtable();      lexstate_S2I = new java.util.Hashtable();      lexstate_I2S = new java.util.Hashtable();      token_mgr_decls = null;      rexprlist = new java.util.Vector();      tokenCount = (int)0;      named_tokens_table = new java.util.Hashtable();      ordered_named_tokens = new java.util.Vector();      names_of_tokens = new java.util.Hashtable();      rexps_of_tokens = new java.util.Hashtable();      simple_tokens_table = new java.util.Hashtable();      maskindex = 0;      jj2index = 0;      maskVals = new Vector();      cline = (int)0;      ccol = (int)0;      actForEof = null;      nextStateForEof = null;   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?