mirror of https://github.com/aamine/cbc
93 lines
2.2 KiB
Java
93 lines
2.2 KiB
Java
package net.loveruby.cflat.ast;
|
|
import net.loveruby.cflat.parser.Token;
|
|
import java.util.*;
|
|
|
|
public class AST extends Node {
|
|
protected String fileName;
|
|
protected Declarations declarations;
|
|
protected Token firstToken;
|
|
|
|
protected ToplevelScope scope;
|
|
protected ConstantTable constantTable;
|
|
|
|
public AST(String fname, Declarations decls, Token t) {
|
|
super();
|
|
fileName = fname;
|
|
declarations = decls;
|
|
firstToken = t;
|
|
scope = new ToplevelScope();
|
|
constantTable = new ConstantTable();
|
|
}
|
|
|
|
public String fileName() {
|
|
return fileName;
|
|
}
|
|
|
|
public Token firstToken() {
|
|
return firstToken;
|
|
}
|
|
|
|
public Iterator types() {
|
|
List result = new ArrayList();
|
|
result.addAll(declarations.defstructs());
|
|
result.addAll(declarations.defunions());
|
|
result.addAll(declarations.typedefs());
|
|
return result.iterator();
|
|
}
|
|
|
|
public Iterator declarations() {
|
|
List result = new ArrayList();
|
|
result.addAll(declarations.funcdecls());
|
|
result.addAll(declarations.vardecls());
|
|
return result.iterator();
|
|
}
|
|
|
|
public Iterator entities() {
|
|
List result = new ArrayList();
|
|
result.addAll(declarations.defvars());
|
|
result.addAll(declarations.defuns());
|
|
return result.iterator();
|
|
}
|
|
|
|
public Iterator variables() {
|
|
return declarations.defvars().iterator();
|
|
}
|
|
|
|
public boolean functionDefined() {
|
|
return !declarations.defuns().isEmpty();
|
|
}
|
|
|
|
public Iterator functions() {
|
|
return declarations.defuns().iterator();
|
|
}
|
|
|
|
public ToplevelScope scope() {
|
|
return scope;
|
|
}
|
|
|
|
public Iterator globalVariables() {
|
|
return scope.globalVariables().iterator();
|
|
}
|
|
|
|
public Iterator commonSymbols() {
|
|
return scope.commonSymbols().iterator();
|
|
}
|
|
|
|
public ConstantTable constantTable() {
|
|
return constantTable;
|
|
}
|
|
|
|
public Location location() {
|
|
return new Location(fileName, 0, 0);
|
|
}
|
|
|
|
protected void _dump(Dumper d) {
|
|
d.printNodeList("variables", variables());
|
|
d.printNodeList("functions", functions());
|
|
}
|
|
|
|
public void accept(ASTVisitor visitor) {
|
|
throw new Error("AST#accept");
|
|
}
|
|
}
|