001    package nl.cwi.sen1.tide.adapters;
002    
003    import aterm.ATerm;
004    import aterm.ATermAppl;
005    
006    public class DebugAdapterRule
007    {
008            public final static int PORT_STEP         = 0;
009            public final static int PORT_STOPPED      = 1;
010            public final static int PORT_STARTED      = 2;
011        
012            public final static int NR_PORT_TYPES = 3;
013            
014            private boolean enabled;
015    
016            private int   id;
017            private int   porttype;
018            private ATerm port;
019            private ATerm cond;
020            private ATerm act;
021            private ATerm tag;
022            
023            public String toString() {
024                    return "rule [\n\tport:" + port +"\n\tcond: " + cond +"\n\tact:" + act + "\n\ttag:" +tag + "\n\tenabled:" + enabled + "\n]";
025            }
026    
027            static int portType(ATerm port)
028            {
029                    String fun = ((ATermAppl)port).getName();
030    
031                    int type;
032    
033                    if(fun.equals("step")) {
034                            type = PORT_STEP;
035                    } else if(fun.equals("stopped")) { 
036                            type = PORT_STOPPED;
037                    } else if(fun.equals("started")) {
038                            type = PORT_STARTED;
039                    } else {
040                            throw new RuntimeException("strange port: " + port);
041                    }
042    
043                    return type;
044            }
045    
046            public DebugAdapterRule(int rid, ATerm port, ATerm cond, ATerm act, ATerm tag, boolean enabled)
047            {
048                    this.id = rid;
049                    this.port = port;
050                    this.cond = cond;
051                    this.act = act;
052                    this.tag = tag;
053                    this.enabled = false;
054                    this.porttype = portType(port);
055            }
056    
057            public boolean isEnabled()
058            {
059                    return enabled;
060            }
061    
062            public void setEnabled(boolean on)
063            {
064                    enabled = on;
065            }
066            public int getId()
067            {
068                    return id;
069            }
070    
071            public int getPortType()
072            {
073                    return porttype;
074            }
075    
076            public ATerm getPort()
077            {
078                    return port;
079            }
080    
081            public ATerm getCondition()
082            {
083                    return cond;
084            }
085    
086            public ATerm getAction()
087            {
088                    return act;
089            }
090    
091            public void modify(ATerm port, ATerm cond, ATerm act, boolean enabled)
092            {
093                    this.port = port;
094                    this.cond = cond;
095                    this.act  = act;
096                    this.enabled = enabled;
097                    this.porttype = portType(port);
098            }
099    
100            public boolean isStepOver()
101            {
102                    return cond.match("higher-equal(start-level,stack-level)") != null;
103            }
104    }