PragmaNode.java
package edu.udel.cis.vsl.tass.ast.impl.statement;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import edu.udel.cis.vsl.tass.ast.IF.ASTNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.AbstractSyntaxTreeIF;
import edu.udel.cis.vsl.tass.ast.IF.expression.StringLiteralNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.statement.PragmaNodeIF;
public class PragmaNode extends StatementNode implements PragmaNodeIF {
private StringLiteralNodeIF string;
private ASTNodeIF nextNode;
public PragmaNode(long id) {
super(id);
}
public PragmaNode(long id, StringLiteralNodeIF string) {
super(id);
this.string = string;
}
@Override
public ASTNodeIF nextNode() {
return nextNode;
}
@Override
public void setNextNode(ASTNodeIF nextNode) {
this.nextNode = nextNode;
}
@Override
public StringLiteralNodeIF string() {
return string;
}
@Override
public void setString(StringLiteralNodeIF string) {
this.string = string;
}
@Override
public int numChildren() {
return 2;
}
@Override
public ASTNodeIF child(int index) throws NoSuchElementException {
switch (index) {
case 0:
return super.child(index);
case 1:
return string;
default:
throw new NoSuchElementException("Node " + id()
+ " does not have a child with index " + index + ".");
}
}
@Override
public void setChild(int i, ASTNodeIF child) throws NoSuchElementException {
switch (i) {
case 0:
super.setChild(i,child);
break;
case 1:
string = (StringLiteralNodeIF)child;
break;
default:
throw new NoSuchElementException("Node " + id()
+ " does not have a child with index " + i + ".");
}
}
@Override
protected String nodeType() {
return "Pragma";
}
@Override
public void toXml(String prefix, PrintWriter out,AbstractSyntaxTreeIF ast) {
super.toXml(prefix,out,ast);
out.println(prefix+"<pn:string>"+string()+"</pn:string>");
}
}