001 package toolbus.atom.tool; 002 003 import toolbus.TBTermFactory; 004 import toolbus.TBTermVar; 005 import toolbus.atom.Atom; 006 import toolbus.atom.Ref; 007 import toolbus.exceptions.ToolBusException; 008 import toolbus.parsercup.PositionInformation; 009 import toolbus.process.ProcessExpression; 010 import toolbus.tool.ToolInstance; 011 import aterm.ATerm; 012 013 public class RecPerfStats extends Atom{ 014 private final Ref toolId; 015 private final Ref result; 016 private ToolInstance toolInstance; 017 018 public RecPerfStats(ATerm toolId, ATerm result, TBTermFactory tbfactory, PositionInformation posInfo){ 019 super(tbfactory, posInfo); 020 021 this.toolId = new Ref(toolId); 022 this.result = new Ref(result); 023 setAtomArgs(new Ref[]{this.toolId, this.result}); 024 025 externalNameAsReceivedByTool = "rec-perf-stats"; 026 } 027 028 public ProcessExpression copy(){ 029 Atom a = new RecPerfStats(this.toolId.value, this.result.value, tbfactory, getPosInfo()); 030 a.copyAtomAttributes(this); 031 032 return a; 033 } 034 035 public void activate(){ 036 toolInstance = null; 037 super.activate(); 038 } 039 040 public boolean execute() throws ToolBusException{ 041 if(!isEnabled()) return false; 042 043 if(toolInstance == null){ 044 ATerm tid = getEnv().getValue((TBTermVar) toolId.value); 045 toolInstance = getToolBus().getToolInstanceManager().get(tid); 046 if(toolInstance == null) return false; 047 } 048 049 if(toolInstance.getPerformanceStats(result.value, getEnv())) return true; 050 051 return false; 052 } 053 }