00001: package clogs.staticanalysis;
00002: 
00003: import clogs.ast.*;
00004: import clogs.util.List;
00005: import clogs.util.Optional;
00006: 
00007: 
00008: public class GatherLabelsInStat
00009: {
00010:   public List<String> labelsDefined = List.nil ();
00011:   public List<String> labelsUsed = List.nil ();
00012: 
00013:   public void gather (Stat stat)
00014:   {
00015:     labelsDefined = labelsDefined.concat (stat.labels);
00016: 
00017:     if (stat instanceof StatCompound) {
00018:       StatCompound statC = (StatCompound) stat;
00019:       for (Stat s : statC.stats) {
00020:         gather (s);
00021:       }
00022: 
00023:     } else if (stat instanceof StatExp) {
00024:       // No labels used.
00025: 
00026:     } else if (stat instanceof StatGoto) {
00027:       StatGoto statG = (StatGoto) stat;
00028:       labelsUsed = labelsUsed.snoc (statG.target);
00029: 
00030:     } else if (stat instanceof StatIf) {
00031:       StatIf statI = (StatIf) stat;
00032:       gather (statI.statT);
00033:       gather (statI.statF);
00034: 
00035:     } else if (stat instanceof StatReturn) {
00036:       // No labels used.
00037: 
00038:     } else if (stat instanceof StatSkip) {
00039:       // No labels used.
00040: 
00041:     } else if (stat instanceof StatWhile) {
00042:       StatWhile statW = (StatWhile) stat;
00043:       gather (statW.stat);
00044: 
00045:     } else {
00046:       throw new RuntimeException ("Missing Stat case: " + stat.getClass ().getName ());
00047:     }
00048:   }
00049: }
00050: 
00051: 
00052: