CSC448: Parsing: Clogs AST: Stat [14/26] |
file:Stat.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: 00005: 00006: public abstract class Stat 00007: { 00008: public final List<String> labels; 00009: 00010: 00011: Stat (List<String> labels) 00012: { 00013: clogs.util.NonNull.check (labels); 00014: this.labels = labels; 00015: } 00016: 00017: 00018: public abstract Stat removeLabels (); 00019: 00020: public abstract Stat addLabel (String label); 00021: 00022: 00023: public Stat addLabels (List<String> labels) 00024: { 00025: Stat result = this; 00026: for (String label : labels.reverse ()) { 00027: result = result.addLabel (label); 00028: } 00029: return result; 00030: } 00031: 00032: 00033: public String toString () 00034: { 00035: PrettyPrinter pp = new PrettyPrinter (); 00036: pp.printStat (this); 00037: return pp.toString (); 00038: } 00039: } 00040:
file:StatCompound.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: import clogs.util.Optional; 00005: 00006: 00007: public class StatCompound extends Stat 00008: { 00009: public final List<Decl> decls; 00010: public final List<Stat> stats; 00011: 00012: 00013: public StatCompound (List<Decl> decls, List<Stat> stats) 00014: { 00015: this (List.<String>nil (), decls, stats); 00016: } 00017: 00018: 00019: StatCompound (List<String> labels, List<Decl> decls, List<Stat> stats) 00020: { 00021: super (labels); 00022: clogs.util.NonNull.check (decls, stats); 00023: this.decls = decls; 00024: this.stats = stats; 00025: } 00026: 00027: 00028: public Stat removeLabels () 00029: { 00030: return new StatCompound (List.<String> nil (), decls, stats); 00031: } 00032: 00033: 00034: public Stat addLabel (String label) 00035: { 00036: return new StatCompound (labels.cons (label), decls, stats); 00037: } 00038: } 00039:
file:StatExp.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: 00005: 00006: public class StatExp extends Stat 00007: { 00008: public final Exp exp; 00009: 00010: 00011: public StatExp (Exp exp) 00012: { 00013: this (List.<String>nil (), exp); 00014: } 00015: 00016: 00017: StatExp (List<String> labels, Exp exp) 00018: { 00019: super (labels); 00020: clogs.util.NonNull.check (exp); 00021: this.exp = exp; 00022: } 00023: 00024: 00025: public Stat removeLabels () 00026: { 00027: return new StatExp (List.<String> nil (), exp); 00028: } 00029: 00030: 00031: public Stat addLabel (String label) 00032: { 00033: return new StatExp (labels.cons (label), exp); 00034: } 00035: } 00036:
file:StatGoto.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: 00005: 00006: public class StatGoto extends Stat 00007: { 00008: public final String target; 00009: 00010: 00011: public StatGoto (String target) 00012: { 00013: this (List.<String>nil (), target); 00014: } 00015: 00016: 00017: StatGoto (List<String> labels, String target) 00018: { 00019: super (labels); 00020: clogs.util.NonNull.check (target); 00021: this.target = target; 00022: } 00023: 00024: 00025: public Stat removeLabels () 00026: { 00027: return new StatGoto (List.<String> nil (), target); 00028: } 00029: 00030: 00031: public Stat addLabel (String label) 00032: { 00033: return new StatGoto (labels.cons (label), target); 00034: } 00035: } 00036:
file:StatIf.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: 00005: 00006: public class StatIf extends Stat 00007: { 00008: public final Exp exp; 00009: public final Stat statT; 00010: public final Stat statF; 00011: 00012: 00013: public StatIf (Exp exp, Stat statT, Stat statF) 00014: { 00015: this (List.<String>nil (), exp, statT, statF); 00016: } 00017: 00018: 00019: StatIf (List<String> labels, Exp exp, Stat statT, Stat statF) 00020: { 00021: super (labels); 00022: clogs.util.NonNull.check (exp, statT, statF); 00023: this.exp = exp; 00024: this.statT = statT; 00025: this.statF = statF; 00026: } 00027: 00028: 00029: public Stat removeLabels () 00030: { 00031: return new StatIf (List.<String> nil (), exp, statT, statF); 00032: } 00033: 00034: 00035: public Stat addLabel (String label) 00036: { 00037: return new StatIf (labels.cons (label), exp, statT, statF); 00038: } 00039: } 00040:
file:StatReturn.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: import clogs.util.Optional; 00005: 00006: 00007: public class StatReturn extends Stat 00008: { 00009: public final Optional<Exp> oe; 00010: 00011: 00012: public StatReturn (Optional<Exp> oe) 00013: { 00014: this (List.<String>nil (), oe); 00015: } 00016: 00017: 00018: StatReturn (List<String> labels, Optional<Exp> oe) 00019: { 00020: super (labels); 00021: clogs.util.NonNull.check (oe); 00022: this.oe = oe; 00023: } 00024: 00025: 00026: public Stat removeLabels () 00027: { 00028: return new StatReturn (List.<String> nil (), oe); 00029: } 00030: 00031: 00032: public Stat addLabel (String label) 00033: { 00034: return new StatReturn (labels.cons (label), oe); 00035: } 00036: } 00037:
file:StatSkip.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: 00005: 00006: public class StatSkip extends Stat 00007: { 00008: public StatSkip () 00009: { 00010: this (List.<String>nil ()); 00011: } 00012: 00013: 00014: StatSkip (List<String> labels) 00015: { 00016: super (labels); 00017: } 00018: 00019: 00020: public Stat removeLabels () 00021: { 00022: return new StatSkip (List.<String> nil ()); 00023: } 00024: 00025: 00026: public Stat addLabel (String label) 00027: { 00028: return new StatSkip (labels.cons (label)); 00029: } 00030: } 00031:
file:StatWhile.java [source] [doc-public] [doc-private]
00001: package clogs.ast; 00002: 00003: import clogs.util.List; 00004: 00005: 00006: public class StatWhile extends Stat 00007: { 00008: public final Exp exp; 00009: public final Stat stat; 00010: 00011: 00012: public StatWhile (Exp exp, Stat stat) 00013: { 00014: this (List.<String>nil (), exp, stat); 00015: } 00016: 00017: 00018: StatWhile (List<String> labels, Exp exp, Stat stat) 00019: { 00020: super (labels); 00021: clogs.util.NonNull.check (exp, stat); 00022: this.exp = exp; 00023: this.stat = stat; 00024: } 00025: 00026: 00027: public Stat removeLabels () 00028: { 00029: return new StatWhile (List.<String> nil (), exp, stat); 00030: } 00031: 00032: 00033: public Stat addLabel (String label) 00034: { 00035: return new StatWhile (labels.cons (label), exp, stat); 00036: } 00037: } 00038: