2007-12-24 16:19:51 +08:00
|
|
|
package net.loveruby.cflat.ast;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class Declarations {
|
2008-08-31 14:18:26 +08:00
|
|
|
protected Set defvars, vardecls, defuns, funcdecls;
|
|
|
|
protected Set defstructs, defunions, typedefs;
|
2007-12-24 16:19:51 +08:00
|
|
|
|
|
|
|
public Declarations() {
|
2008-08-31 14:18:26 +08:00
|
|
|
defvars = new LinkedHashSet();
|
|
|
|
vardecls = new LinkedHashSet();
|
|
|
|
defuns = new LinkedHashSet();
|
|
|
|
funcdecls = new LinkedHashSet();
|
|
|
|
defstructs = new LinkedHashSet();
|
|
|
|
defunions = new LinkedHashSet();
|
|
|
|
typedefs = new LinkedHashSet();
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void add(Declarations decls) {
|
2008-08-31 14:18:26 +08:00
|
|
|
updateSet(vardecls, decls.vardecls());
|
|
|
|
updateSet(funcdecls, decls.funcdecls());
|
|
|
|
updateSet(defstructs, decls.defstructs());
|
|
|
|
updateSet(defunions, decls.defunions());
|
|
|
|
updateSet(typedefs, decls.typedefs());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateSet(Set s, List items) {
|
|
|
|
Iterator i = items.iterator();
|
|
|
|
while (i.hasNext()) {
|
|
|
|
s.add(i.next());
|
|
|
|
}
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addDefvar(DefinedVariable var) {
|
|
|
|
defvars.add(var);
|
|
|
|
}
|
|
|
|
|
2008-01-21 00:19:13 +08:00
|
|
|
public void addDefvars(List vars) {
|
2008-08-31 14:18:26 +08:00
|
|
|
updateSet(defvars, vars);
|
2008-01-21 00:19:13 +08:00
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public List defvars() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(defvars);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addVardecl(UndefinedVariable var) {
|
|
|
|
vardecls.add(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List vardecls() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(vardecls);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addDefun(Function func) {
|
|
|
|
defuns.add(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List defuns() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(defuns);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addFuncdecl(UndefinedFunction func) {
|
|
|
|
funcdecls.add(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List funcdecls() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(funcdecls);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addDefstruct(StructNode n) {
|
|
|
|
defstructs.add(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List defstructs() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(defstructs);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addDefunion(UnionNode n) {
|
|
|
|
defunions.add(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List defunions() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(defunions);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addTypedef(TypedefNode n) {
|
|
|
|
typedefs.add(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List typedefs() {
|
2008-08-31 14:18:26 +08:00
|
|
|
return new ArrayList(typedefs);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
}
|