package jcircus.benchmarking; import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; import net.sourceforge.czt.circus.util.Factory; import net.sourceforge.czt.typecheck.z.ErrorAnn; import net.sourceforge.czt.z.ast.Expr; import net.sourceforge.czt.z.ast.RefExpr; import net.sourceforge.czt.z.ast.Spec; import jcircus.JCircusController; import jcircus.JCircusControllerFrame; import jcircus.exceptions.FailParsingException; import jcircus.exceptions.FailTranslationException; import jcircus.exceptions.FailTypeCheckingException; import jcircus.exceptions.JCircusException; import jcircus.exceptions.TranslationCancelledException; import jcircus.gui.JCircusFrame; import jcircus.gui.ParametersDialog; import jcircus.parallelism.ProcHiddenFromGUIEnv; import jcircus.translator.ProcInfoUpdater; import jcircus.translator.Translator2Java; import jcircus.util.Constants; import jcircus.util.Error; import jcircus.util.MathToolkitConstants; import jcircus.util.ProcInfo; public class JCircusControllerBench extends JCircusController { Spec spec = null; JCircusFrame _jCircusFrame; private boolean createMain = false; public void setCreateMain (String c) { if (c.equals("true")) createMain = true; else { createMain = false; } } public JCircusControllerBench () { _jCircusFrame = new JCircusFrame(JCircusControllerBench.this); } protected void translate2Java (String projectDir, String projectName, Spec spec, String compl, boolean useBarriers, boolean parallelism, boolean bench) throws FailTranslationException, TranslationCancelledException, JCircusException { List procInfoList = new ArrayList (); ProcHiddenFromGUIEnv prochid = new ProcHiddenFromGUIEnv (); /*ProcInfoUpdater.initProcInfoAndCreateMainEnv (_jCircusFrame.getProcCreateMainEnv(), procInfoList, spec, parallelism, createMain); if (!createMain) { _jCircusFrame.promptForMainProcessesPCME (procInfoList); }*/ _translator = new Translator2Java(projectDir, projectName, spec, compl, useBarriers, parallelism, bench, _jCircusFrame/*.getProcCreateMainEnv()*/, createMain); _translator.translate(true); procInfoList = _translator.getProcInfoList(); /*if (!createMain) _jCircusFrame.promptForMainProcesses(procInfoList);*/ for (int i = 0; i < procInfoList.size(); i++) { ProcInfo procInfo = procInfoList.get(i); if (createMain) { procInfo.setCreateMain(true); } if (procInfo.getCreateMain() == true && procInfo.getParameters() != null && !procInfo.getParameters().isEmpty() ) { if (!createMain) _jCircusFrame.promptForParameters(procInfo); } } // Create the source code files _translator.createSources(); System.out.println ("Time Millis FINAL ::: " + System.currentTimeMillis()); } protected void reportMessage (String message) { //_jCircusFrame.reportMessage(message); } /** * */ protected void reportParsingErrors(List errors) { String message = parsingErrorMessage(errors); reportMessage(message); } /** * */ protected void reportTypeCheckingErrors(List errors) { String message = typeCheckingErrorMessage(errors); reportMessage(message); } /** * */ protected void reportTranslationErrors(List errors) { String message = translationErrorMessage(errors); reportMessage(message); } public String codeForParameter(String expression, Expr typeExpr) throws FailParsingException, FailTypeCheckingException { String code = ""; // For the moment, typeExpr will be always a reference. This will be // changed in the future. Probably this method will receive the actual // Type, instead of the type expression. assert(typeExpr instanceof RefExpr); String typeExprSt = ((RefExpr) typeExpr).getName().toString();//.getRefName().toString(); if (typeExprSt.equals(MathToolkitConstants.NAT) || typeExprSt.equals(MathToolkitConstants.NUM) || typeExprSt.equals(MathToolkitConstants.ARITHMOS)) { // Number try { // Simulate parsing/typeChecking here int number = Integer.parseInt(expression); code = "new " + Constants.CLS_CIRCNUM + "(" + number + ")"; } catch (NumberFormatException nfe) { // Error List errors = new Factory().list("Expression is not a number."); throw new FailParsingException(errors); } } else { if (_translator.getEnvironment().isElementFreeType(typeExprSt, expression)) { // Simulate parsing/typeChecking here code = "new " + typeExprSt + "(" + typeExprSt + "." + expression + ")"; } else { // Error List errors = new Factory().list("Expression is not an element of free type."); throw new FailParsingException(errors); } } return code; } /** * Cancel the translation. */ public void cancelTranslation () throws TranslationCancelledException { throw new TranslationCancelledException(); } }