📄 namespace.java
字号:
package ast;
public class NameSpace {
private java.util.Hashtable objects = null;
private java.util.Vector vobjects = null;
private NameSpace parent = null;
/**
* setup and link to one new namespace.
*
* @param parent parent-namespace
*/
public NameSpace (NameSpace parent) {
this.parent = parent;
objects = new java.util.Hashtable ();
vobjects = new java.util.Vector ();
}
private String name = null;
/**
* put Name
*
* @param name the name is namespace
*/
public void setName (String name) {
this.name = name;
}
public String getName () {
return name;
}
/**
* enter one Object in namespace
*/
public void addObject (ast.declaration.JSubObject obj) {
String key = obj.getName();
Object o = objects.get (key);
if (o == null) {
objects.put (key, obj);
vobjects.addElement (obj);
obj.setParent (this);
}
else
util.Error.e1 ("name already defined " + key);
}
/**
* find one Object in Namespace
*
* @return null or the location of Object
*/
public ast.declaration.JSubObject getObject (String key) {
return (ast.declaration.JSubObject)objects.get (key);
}
/**
* amount All Object in namespace
*
* @return the Vektor with Object
*/
public java.util.Vector getObjects () {
return vobjects;
}
/**
* number the definition Object amount
*
* @return number of definition Object
*/
public int getNoOfLocals () {
return objects.size ();
}
/**
* display all Object
*
*/
public void dump () {
for (int i = 0; i < vobjects.size (); i++) {
ast.declaration.JSubObject oe = (ast.declaration.JSubObject)vobjects.elementAt (i);
oe .dump ("");
}
}
/**
* generate XML for this namespace
*
* @param p displaycurrent
* @param prefix insert the row to the display
*/
public void genXML (java.io.PrintStream p, String prefix) {
p.println (prefix + "<namespace>");
for (int i = 0; i < vobjects.size (); i++) {
ast.declaration.JSubObject oe = (ast.declaration.JSubObject)vobjects.elementAt (i);
oe .genXML (p, prefix + " ");
}
p.println (prefix + "</namespace>");
}
/**
* Codegeneration for the Namenspace.
* Dispaly all static Variable and Codegeneration for Method.
*
*/
public void codegen () {
for (int i = 0; i < vobjects.size (); i++) {
ast.declaration.JSubObject oe = (ast.declaration.JSubObject)vobjects.elementAt (i);
if (oe instanceof ast.declaration.StaticVariable) {
ast.declaration.StaticVariable variable = (ast.declaration.StaticVariable)oe;
variable.codegen();
}
}
for (int i = 0; i < vobjects.size (); i++) {
ast.declaration.JSubObject oe = (ast.declaration.JSubObject)vobjects.elementAt (i);
if (oe instanceof ast.declaration.StaticMethod) {
ast.declaration.StaticMethod method = (ast.declaration.StaticMethod)oe;
method.codegen();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -