⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staticmethod.java

📁 一个JAVA编写的简单编译器
💻 JAVA
字号:
package ast.declaration;

public class StaticMethod extends ast.declaration.JSubObject {
  private boolean isPublic = false;
  private ast.NameSpace localDeclarations = null;
  private ast.IJSubNode statements = null;

  public StaticMethod (String name, boolean isPublic, int type) {
    super (name, type);
    this.isPublic = isPublic;
  }
  
  public String getMethodName () {
    String name = getName ();
    StringBuffer buffer = new StringBuffer (name.length ());
    for (int i = 0; i < name.length(); i++) {
      char c = name.charAt (i);
      if (c == '.')
        buffer.append ('/');
      else
        buffer.append (c);
    }
    return buffer.toString ();
  }  

  public void dump (String prefix) {
    System.out.print (prefix + "method ");
    super.dump (prefix);
    localDeclarations.dump ();
    if (statements != null)
      statements.dump (prefix + "  ");
    System.out.println ("endmethod ");
  }

  public void genXML (java.io.PrintStream p, String prefix) {
    p.println (prefix + "<staticmethod>");
    super.genXML (p, prefix + "  ");
    localDeclarations.genXML (p, prefix + "  ");
    if (statements != null)
      statements.genXML (p, prefix + "  ");
    p.println (prefix + "</staticmethod>");
  }  

  public void genXMLSimple (java.io.PrintStream p, String prefix) {
    super.genXML (p, prefix);
    p.println (prefix + "<signature>");
    p.println (prefix + getSignature ());
    p.println (prefix + "</signature>");
    
  }  

  public String getXMLType () {
    return "staticmethod";
  }
 
  public void setNameSpace (ast.NameSpace s) {
    localDeclarations = s;
  }
  
  public java.util.Vector getDeclarations () {
    return localDeclarations.getObjects ();
  }

  public void setStatements (ast.IJSubNode statements) {
    this.statements = statements;
  }
  
  public ast.IJSubNode getStatements () {
    return statements;
  }
  
  public void codegen () {
   
    if (getName().indexOf ('.') >= 0)
      return;
    if (getName ().equals ("main")) {
      codegen.WriteCode.genMain (localDeclarations.getNoOfLocals(), statements.getDepth());
    } else
      codegen.WriteCode.genMethodHeader (
        getAttribute(), 
        getName (), 
        getSignature (), 
        getType (),
        localDeclarations.getNoOfLocals (),
        statements.getDepth ()
        );
    if (statements != null)
      statements.codegen ();
    codegen.WriteCode.genMethodTrailer (getType ());
  }

  public String getStoreString () {
    return null;
  }
  public String getLoadString () {
    return null;
  }

  public String getSignature () {
    java.util.Vector objs = getDeclarations ();
    if (objs == null)
      return "??no Decls";
    StringBuffer signature = new StringBuffer ();
    for (int i = 0; i < objs.size(); i++) {
      ast.declaration.JSubObject d = (ast.declaration.JSubObject)objs.elementAt(i);
      if (d.isParameter())
        signature.append ('I');
    }
    return signature.toString();
  }
  public String getAttribute () {
    if (isPublic)
      return "public";
    else
      return "";  
  }
  public boolean isParameter () {
    return false;
  }
}

⌨️ 快捷键说明

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