package jcircus.visitor; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.Vector; import javax.swing.JOptionPane; //import jcircus.environment.ChanMSEnv; import jcircus.environment.ChanInfoEnv; import jcircus.environment.ChanUseEnv; import jcircus.environment.Environment; import jcircus.environment.ProcChanEnv; import jcircus.environment.NameTypeEnv; import jcircus.environment.ProcChanUseEnv; import jcircus.exceptions.ChanDefOtherChanSyncException; import jcircus.exceptions.ChanDefOtherChanUseException; import jcircus.exceptions.ChanSyncUnificationException; import jcircus.exceptions.ChanUseUnificationException; import jcircus.exceptions.DifferentCardinalitiesException; import jcircus.exceptions.InvalidFormatCommException; import jcircus.exceptions.runtime.InvalidSubTypeException; import jcircus.exceptions.MoreThanOneWriterException; import jcircus.exceptions.runtime.UnrecoveredErrorException; import jcircus.exceptions.runtime.VisitingMethodNotDefinedException; import jcircus.generators.GCArrayGenerator; import jcircus.generators.GPSEGenerator; import jcircus.newutil.ChanSetUtil; import jcircus.newutil.ChoiceUtil; import jcircus.newutil.DeclUtil; import jcircus.newutil.ExprUtil; import jcircus.newutil.PrinterUtil; import jcircus.parallelism.CopyProcessAnn; //import jcircus.interleaving.OfferedEventsInfo; //import jcircus.parallelismandrenaming.Index2PrefActEnv; import jcircus.parallelism.ParallelismUpdater; import jcircus.parallelism.FriendshipSets; import jcircus.util.CircusType; import jcircus.util.Constants; import jcircus.util.Error; import jcircus.util.ErrorMessage; //import jcircus.util.GuardsGenerator; import jcircus.util.IdCircusProcessGenerator; import jcircus.util.ChanUse; import jcircus.util.MathToolkitConstants; import jcircus.util.NameType; import jcircus.util.ChanSync; import jcircus.util.Util; import jcircus.util.annotations.IdCircusProcessAnn; import net.sourceforge.czt.base.ast.ListTerm; import net.sourceforge.czt.base.ast.Term; import net.sourceforge.czt.base.impl.ListTermImpl; import net.sourceforge.czt.circus.ast.Action1; import net.sourceforge.czt.circus.ast.Action2; import net.sourceforge.czt.circus.ast.ActionD; import net.sourceforge.czt.circus.ast.ActionIte; import net.sourceforge.czt.circus.ast.ActionPara; import net.sourceforge.czt.circus.ast.AssignmentCommand; import net.sourceforge.czt.circus.ast.BasicAction; //import net.sourceforge.czt.circus.ast.BasicChannelSet; import net.sourceforge.czt.circus.ast.BasicChannelSetExpr; //Sam import net.sourceforge.czt.circus.ast.BasicProcess; import net.sourceforge.czt.circus.ast.CallAction; import net.sourceforge.czt.circus.ast.CallProcess; //import net.sourceforge.czt.circus.ast.CallType; //Substitu�do por CallUsage import net.sourceforge.czt.circus.ast.CallUsage; import net.sourceforge.czt.circus.ast.ChannelDecl; import net.sourceforge.czt.circus.ast.ChannelPara; import net.sourceforge.czt.circus.ast.ChannelSet; import net.sourceforge.czt.circus.ast.ChannelSetPara; import net.sourceforge.czt.circus.ast.CircusAction; import net.sourceforge.czt.circus.ast.CircusProcess; //import net.sourceforge.czt.circus.ast.CommType; //deixa em stand by tamb�m import net.sourceforge.czt.circus.ast.CommUsage; //deixa em stand by tamb�m import net.sourceforge.czt.circus.ast.Communication; import net.sourceforge.czt.circus.ast.DotField; import net.sourceforge.czt.circus.ast.ExtChoiceAction; import net.sourceforge.czt.circus.ast.Field; import net.sourceforge.czt.circus.ast.GuardedAction; import net.sourceforge.czt.circus.ast.HideProcess; import net.sourceforge.czt.circus.ast.IfGuardedCommand; import net.sourceforge.czt.circus.ast.InputField; import net.sourceforge.czt.circus.ast.MuAction; import net.sourceforge.czt.circus.ast.NameSetPara; //import net.sourceforge.czt.circus.ast.OutputField; import net.sourceforge.czt.circus.ast.CircusActionList; import net.sourceforge.czt.circus.ast.CircusChannelSet; import net.sourceforge.czt.circus.ast.CircusCommunicationList; import net.sourceforge.czt.circus.ast.CircusFieldList; import net.sourceforge.czt.circus.ast.CommPattern; import net.sourceforge.czt.circus.ast.CommunicationList; import net.sourceforge.czt.circus.ast.FieldList; import net.sourceforge.czt.circus.ast.InterleaveAction; import net.sourceforge.czt.circus.ast.OutputFieldAnn; //By Sam's import net.sourceforge.czt.circus.ast.ParAction; import net.sourceforge.czt.circus.ast.ParProcess; import net.sourceforge.czt.circus.ast.ParallelAction; import net.sourceforge.czt.circus.ast.ParamAction; import net.sourceforge.czt.circus.ast.ParamProcess; import net.sourceforge.czt.circus.ast.PrefixingAction; import net.sourceforge.czt.circus.ast.Process1; import net.sourceforge.czt.circus.ast.Process2; import net.sourceforge.czt.circus.ast.ProcessD; import net.sourceforge.czt.circus.ast.ProcessIdx; import net.sourceforge.czt.circus.ast.ProcessIte; import net.sourceforge.czt.circus.ast.ProcessPara; //import net.sourceforge.czt.circus.ast.RefChannelSet; import net.sourceforge.czt.circus.ast.ChannelSet; //Added by Sam, mas n�o sei, tou em d�vida em rela��o ao de cima import net.sourceforge.czt.circus.ast.RenameProcess; import net.sourceforge.czt.circus.ast.VarDeclCommand; import net.sourceforge.czt.circus.impl.ActionParaImpl; import net.sourceforge.czt.circus.impl.BasicProcessImpl; import net.sourceforge.czt.z.ast.ApplExpr; /*********/ import net.sourceforge.czt.z.ast.AxPara; import net.sourceforge.czt.z.ast.BindExpr; /*********/ import net.sourceforge.czt.z.ast.Box; import net.sourceforge.czt.z.ast.Branch; import net.sourceforge.czt.z.ast.CondExpr; /*********/ import net.sourceforge.czt.z.ast.ConstDecl; import net.sourceforge.czt.z.ast.Decl; import net.sourceforge.czt.z.ast.DeclList; import net.sourceforge.czt.z.ast.ExprList; import net.sourceforge.czt.z.ast.LatexMarkupPara; import net.sourceforge.czt.z.ast.Name; import net.sourceforge.czt.z.ast.NameList; import net.sourceforge.czt.z.ast.NarrPara; import net.sourceforge.czt.z.ast.NarrSect; import net.sourceforge.czt.z.ast.ParaList; import net.sourceforge.czt.z.ast.ProdExpr; /*********/ import net.sourceforge.czt.z.ast.Sect; import net.sourceforge.czt.z.ast.SetExpr; import net.sourceforge.czt.z.ast.ZBranchList; import net.sourceforge.czt.z.ast.ZDeclList; //Acrescentado por quem?? Sam! import net.sourceforge.czt.z.ast.ZExprList; import net.sourceforge.czt.z.ast.ZFreetypeList; import net.sourceforge.czt.z.ast.ZName/*DeclName*/; import net.sourceforge.czt.z.ast.Expr; /*********/ import net.sourceforge.czt.z.ast.Expr0N; /*********/ import net.sourceforge.czt.z.ast.Expr1; /*********/ import net.sourceforge.czt.z.ast.Expr2; /*********/ import net.sourceforge.czt.z.ast.ExprPred; /*********/ import net.sourceforge.czt.z.ast.Fact; import net.sourceforge.czt.z.ast.FreePara; import net.sourceforge.czt.z.ast.Freetype; import net.sourceforge.czt.z.ast.MemPred; import net.sourceforge.czt.z.ast.ZParaList; //import net.sourceforge.czt.z.ast.NameExprPair; //Como diabos vai ser esse???????????????? import net.sourceforge.czt.z.ast.NegPred; import net.sourceforge.czt.z.ast.NumExpr; /*********/ import net.sourceforge.czt.z.ast.Para; import net.sourceforge.czt.z.ast.Pred; import net.sourceforge.czt.z.ast.Pred2; import net.sourceforge.czt.z.ast.RefExpr; /*********/ import net.sourceforge.czt.z.ast.ZNameList; import net.sourceforge.czt.z.ast.ZSchText; //import net.sourceforge.czt.z.ast.RefName; //Provavelmente aqui � s� comentar, pq o ZName j� est� declarado import net.sourceforge.czt.z.ast.SchExpr; /*********/ import net.sourceforge.czt.z.ast.SchText; import net.sourceforge.czt.z.ast.Spec; import net.sourceforge.czt.z.ast.VarDecl; import net.sourceforge.czt.z.ast.ZSect; import net.sourceforge.czt.z.util.Factory; import jcircus.util.SignatureExpression; import net.sourceforge.czt.z.ast.NameTypePair; import net.sourceforge.czt.z.ast.Signature; import net.sourceforge.czt.z.impl.LatexMarkupParaImpl; import net.sourceforge.czt.z.impl.NarrParaImpl; import net.sourceforge.czt.z.impl.NarrSectImpl; import net.sourceforge.czt.z.impl.ZParaListImpl; import net.sourceforge.czt.z.impl.ZSectImpl; //import newjcircusutil.barrier.G4BGenerator; //import newjcircusutil.barrier.GBGenerator; import jcircus.complementaryenvs.CallProc2ChannelSetEnv; import jcircus.complementaryenvs.ChanComplexCommEnv; import jcircus.complementaryenvs.ChanDimEnv; import jcircus.complementaryenvs.ChanDotFieldEnv; import jcircus.complementaryenvs.ChanExtChoiceEnv; import jcircus.complementaryenvs.ChanForcedInterleavingEnv; import jcircus.complementaryenvs.ChanTransMSEnv; import jcircus.complementaryenvs.PId2PNameEnv; import jcircus.complementaryenvs.ParProcessEnv; import jcircus.complementaryenvs.ProcCreateMainEnv; import jcircus.complementaryenvs.ProcMuIndexEnv; import jcircus.complementaryenvs.ProcName2ProcChanEnv; import jcircus.complementaryenvs.TypeSizeEnv; //import jcircus.complementaryenvs.MinMaxEnv; import jcircus.complementaryenvs.ProcProcessParaEnv; //import jcircus.complementaryenvs.Proc2HasIdEnv; import jcircus.complexcomms.*; /** * EnvLoadingVisitor.java * * Performs the pre-processing of the Circus specification. * * @author Angela Freitas, updated by Samuel Barrocas * */ //public class EnvLoadingVisitor implements EnvLoadingVisitorInterface { //By Angela public class EnvLoadingVisitor implements EnvLoadingVisitorInterface { //Sam's private ProcMuIndexEnv _muActs2Indexes = new ProcMuIndexEnv (); public ProcMuIndexEnv getMuActs2Indexes () { return this._muActs2Indexes; } int mucounter = 0; Spec spec; String currentProcessName; String projectDir; String projectName; Vector absGens = new Vector (); Vector ccMapsGens = new Vector (); public Vector getAbsGens () { return this.absGens; } public Vector getccMapsGens () { return this.ccMapsGens; } public String getProjectDir () { return this.projectDir; } public String getProjectName () { return this.projectName; } public String getSpecNameOnTranslation () { return this.specNameOnTranslation; } String specNameOnTranslation; ProcessPara processPara; //Sam's private ZName/*DeclName*/ _currentProc = null; private ZName/*DeclName*/ _currentAct = null; private String _stateName = null; private Environment _env; // Environment for channels and types. private boolean _extChoice = false; // Flag that indicates an external choice. private String _currentRecAct; private Factory _factory; private boolean _globalScope; private List _errors; private ProcCreateMainEnv pcme; public ProcCreateMainEnv getProcCreateMainEnv () { return this.pcme; } public void setProcCreateMainEnv (ProcCreateMainEnv pcmeparam) { this.pcme = pcmeparam; } private ChanTransMSEnv chanMSEnv = new ChanTransMSEnv (); //Sam public ChanTransMSEnv getChanMultiSyncEnv () { //Sam return this.chanMSEnv; } private ParProcessEnv parprocEnv = new ParProcessEnv (); public ParProcessEnv getEnvLoadingParProcessEnv () { return this.parprocEnv; } private PId2PNameEnv p2pId = new PId2PNameEnv (); public PId2PNameEnv getPId2PNameEnv () { return this.p2pId; } private ProcName2ProcChanEnv pn2pce = new ProcName2ProcChanEnv (); public ProcName2ProcChanEnv getProcName2ProcChanEnv () { return this.pn2pce; } private CallProc2ChannelSetEnv cp2cse = new CallProc2ChannelSetEnv (); public CallProc2ChannelSetEnv getCallProc2ChannelSetEnv () { return this.cp2cse; } //private Proc2HasIdEnv proc2HasIdEnv = new Proc2HasIdEnv(); //Sam's public void addProcToProcess1Env (ProcessPara processPara) { CircusProcess process = processPara.getCircusProcess(); if (process instanceof ParProcess) { this.parprocEnv.put(processPara.getZName().toString(), true); } else { this.parprocEnv.put(processPara.getZName().toString(), false); } } private ProcProcessParaEnv procProcessParaEnv = new ProcProcessParaEnv (); //By Samuel Barrocas, 16/12/2010, 17:25hs. public ProcProcessParaEnv getProcProcessParaEnv () { //By Samuel Barrocas, 16/12/2010, 17:25hs return this.procProcessParaEnv; } public void setProcProcessParaEnv (ProcProcessParaEnv env) { //By Samuel Barrocas, 16/12/2010, 17:25hs this.procProcessParaEnv = env; } private ChanDotFieldEnv chanDotFieldEnv = new ChanDotFieldEnv (); public ChanDotFieldEnv getChanDotFieldEnv () { return this.chanDotFieldEnv; } //private int barrierDim; //Sam's. Sam comment: Aqui acho que vou tirar depois private boolean alreadyDefinedId = false; private int nCommValues; //Sam's private ChanDimEnv chanDimEnv = new ChanDimEnv (); //Sam's //private MinMaxEnv minMaxEnv = new MinMaxEnv (); //Sam's //private ChanMSEnv chanMSEnv = new ChanMSEnv (); //Sam's Channel2TypeEnvironment chanTypeEnv = new Channel2TypeEnvironment (); public Channel2TypeEnvironment getChanTypeEnv4CC () { return this.chanTypeEnv; } private int minComm, maxAbsValueComm; public int getMinComm () { return this.minComm; } public int getMaxAbsValueComm () { return this.maxAbsValueComm; } public ChanDimEnv getChanDimEnv () { //Sam's return this.chanDimEnv; } private ChanForcedInterleavingEnv cfie = new ChanForcedInterleavingEnv (); private ChanComplexCommEnv ccce = new ChanComplexCommEnv (); public ChanForcedInterleavingEnv getChanForcedInterleavingEnv () { return this.cfie; } public ChanComplexCommEnv getChanComplexCommEnv () { return this.ccce; } private ChanExtChoiceEnv cece = new ChanExtChoiceEnv (); //Sam's public void setChanExtChoiceEnv (ChanExtChoiceEnv cece) { //Sam's this.cece = cece; } public ChanExtChoiceEnv getChanExtChoiceEnv () { return this.cece; } TypeSizeEnv tse = new TypeSizeEnv (); public TypeSizeEnv getTypeSizeEnv () { return this.tse; } //private Index2PrefActEnv pa2ie; /*public Index2PrefActEnv getPrefAct2IndexEnv () { return this.pa2ie; }*/ boolean useBarriers; /** * Return the list of errors. */ public List getErrors() { return this._errors; } /** * Methods to report errors. */ private void reportError(Error error) { _errors.add(error); } private void reportFatalError(Error error) throws UnrecoveredErrorException { reportError(error); throw new UnrecoveredErrorException("Error during the environment loading."); } private void reportFatalError(Error error, Exception e) throws UnrecoveredErrorException { reportError(error); throw new UnrecoveredErrorException("Error during the environment loading.", e); } /** * Constructor for class EnvLoadingVisitor. * */ boolean bench; public EnvLoadingVisitor(Environment Environment, String projectDir, String projectName, String specNameOnTranslation /*<-- Sam*/, boolean useBarriers, boolean bench) { //Construtor de EnvLoadingVisitor this.bench = bench; _env = Environment; _factory = new Factory(); _globalScope = true; _stateName = null; _errors = new ArrayList(); this.projectDir = projectDir; this.projectName = projectName; this.specNameOnTranslation = specNameOnTranslation; loadMathToolkit(); this.minComm = 0; this.useBarriers = useBarriers; } public EnvLoadingVisitor(Environment environment) { this (environment, "", "", "", true, false); } /** * Just in case this visitor is called for a node that has not been considered yet. * * @param term * @return */ public Object visitTerm(Term term) { throw new VisitingMethodNotDefinedException(term.getClass(), this.getClass()); } /** ************************************************************************************************************** * Term A Tree. * *************************************************************************************************************** */ /** * */ public Object visitSpec(Spec spec) { //Visita a especificacao. Aqui eh o ponto mais alto da hierarquia de visitadores this.spec = spec; System.out.print (""); ZSect zSect; if (spec.getSect().get(0) instanceof NarrSect) zSect = (ZSect) spec.getSect().get(1); else zSect = (ZSect) spec.getSect().get(0); ZParaList paras = (ZParaList) zSect.getParaList(); for (int i = 0; i < paras.size(); i++) { if (!(paras.get(i) instanceof NarrPara || paras.get(i) instanceof LatexMarkupPara)) { Para para = (Para) paras.get(i); //Aqui vai invocar os visitadores dos par�grafos que nao forem narrativos (com texto), ou de tags de Latex para.accept(this); } } return null; } public Object visitLatexMarkupPara (LatexMarkupPara lmp) { ListTerm directive = lmp.getDirective(); return null; } public Object visitLatexMarkupParaImpl (LatexMarkupParaImpl lmpi) { return null; } /** * */ public Object visitFreetype(Freetype freetype) { //Visita os parágrafos de tipos livres. ZBranchList branches = (ZBranchList)(freetype.getBranchList()); ZName declNameFreetype = freetype.getZName(); this.tse.put(declNameFreetype.toString(), branches.size()); // Add this freeType to the freeTypeEnvironment _env.freeTypesEnvironmentAdd(freetype); //Adiciona o tipo livre � lista de tipos livres // Declare the free type in the TypeEnvironment CircusType circusType = new CircusType(_factory.createPowerExpr( _factory.createRefExpr(_factory.createZName(declNameFreetype.toString())))); //Sam's //Util.createCircusType(this.factory_.createPowerExpr(), this.environment_); this._env.declareName( this._factory.createZName(declNameFreetype.toString()), NameType.FreeType, circusType); for (int i = 0; i < branches.size(); i++) { Branch branch = (Branch) branches.get(i); ZName declNameBranch = branch.getZName(); //retorna sam1 ou sam2 Expr expr = branch.getExpr(); Expr type; RefExpr refExprNameFreeType = this._factory.createRefExpr( //this._factory.createRefName(declNameFreetype)); //�ngela's this._factory.createZName(declNameFreetype)); // Meuzis, Sam's if (expr != null) { List list = new ArrayList(); list.add(expr); list.add(declNameFreetype); type = this._factory.createPowerExpr( this._factory.createProdExpr (expr, refExprNameFreeType) ); //new PowerSet(new CartesianProduct(list)); } else { // RefExpr type = refExprNameFreeType; } // Only the first element will the its type // (the free type) added to the type list boolean b = (i == 0) ? true : false; // Declare the branch of the free type in the TypeEnvironment this._env.declareName( //this._factory.createDeclName(declNameBranch.toString()), //Angela's this._factory.createZName(declNameBranch.toString()), //Sam's NameType.ElemFreeType, new CircusType(type), b); System.out.print(""); } return null; } /** * Visits a schema text and returns its signature. * */ public Object visitSchText(SchText schText) { //JOptionPane.showMessageDialog (null, "Visitou SchText"); Signature result = this._factory.createSignature(Util.createEmptyListTerm()); //ListTerm decls = schText.getDecl(); //By Angela! /*ListTerm*/ZDeclList decls = ((ZSchText)schText).getZDeclList().getDecl(); //By euzis, modificando a linha acima // Pred pred = schText.getPred(); //By Angela!! Pred pred = ((ZSchText)schText).getPred(); //By euzis, modificando a linha de cima!! ListTerm nameTypePairs; // Gets the annotation NameType nameType = Util.getAndRemoveNameTypeAnn(schText); // Open the scope of the schema _env.openScope(); if(decls != null) { for (int i = 0; i < decls.size(); i++) { /** * If this is a SchText for a schema (NameType == StateComp) * */ Decl decl = (Decl) decls.get(i); // Adds annotation Util.addNameTypeAnn(decl, nameType); // Visits the declaration Signature signature = (Signature) decl.accept(this); // Add to the signature //if (signature.getNameTypePair() != null) //Acrescentado por Sam result.getNameTypePair().addAll(signature.getNameTypePair()); //DESCOMENTAR DEPOIS!!! System.out.println ("Passou por aqui"); } } if (pred != null) { pred.accept(this); } // Close the scope of the schema _env.closeScope(); return result; } /** ************************************************************************************************************** * Decl Tree. * *************************************************************************************************************** */ /** * */ public int exhibitOptionPane4MaxAbsValueComm (Expr expr) { boolean shown = false; int maxabscomm = -1; if (expr instanceof ProdExpr) { ZExprList exprList = ((ProdExpr)expr).getZExprList(); int size = exprList.size(); for (int i = 0; i < size; i++) { Expr subexpr = exprList.get(i); if (subexpr instanceof RefExpr) { if (!shown && ((RefExpr)subexpr).getZName().toString().equals("ℕ")) { String str = JOptionPane.showInputDialog("Enter maximum absolute value to be communicated:"); maxabscomm = Integer.parseInt (str); System.out.println ("Time Millis 1 ::: " + System.currentTimeMillis()); } else { maxabscomm = tse.get(((RefExpr)subexpr).getZName().toString()); System.out.println ("Time Millis 1 ::: " + System.currentTimeMillis()); } } else if (subexpr instanceof SetExpr) { SetExpr setexpr = (SetExpr)subexpr; maxabscomm = setexpr.getZExprList().size(); } } } else if (expr instanceof RefExpr) { if (!shown && ((RefExpr)expr).getZName().toString().equals("ℕ")) { String str = JOptionPane.showInputDialog("Enter maximum absolute value to be communicated:"); System.out.println ("Time Millis 1 ::: " + System.currentTimeMillis()); maxabscomm = Integer.parseInt(str); shown = true; } else { maxabscomm = tse.get(((RefExpr)expr).getZName().toString()); System.out.println ("Time Millis 1 ::: " + System.currentTimeMillis()); } } else if (expr instanceof SetExpr) { SetExpr setexpr = (SetExpr)expr; maxabscomm = setexpr.getZExprList().size(); System.out.println ("Time Millis 1 ::: " + System.currentTimeMillis()); } return maxabscomm; } public int dim = 0; public Object visitChannelDecl(ChannelDecl channelDecl) { //Visita uma declara��o de canal. if (channelDecl.getExpr() instanceof RefExpr) { dim = 1; } else if (channelDecl.getExpr() instanceof ProdExpr) dim = ((((ZExprList)((ProdExpr)channelDecl.getExpr()).getExprList()).size()) > dim)? ((ZExprList)((ProdExpr)channelDecl.getExpr()).getExprList()).size() : dim; else {/*TODO to be done...*/} //GCArrayGenerator.generate (dim, projectDir + "\\" + projectName + "\\src\\" + projectName + "\\typing\\GCArray.java", specNameOnTranslation); //(new CCEnvsGenerator("paper", "src", projectDir)).generateClasses(); ZNameList genNames = channelDecl.getZGenFormals(); //Sam's System.out.print(""); //ZNameList decl = channelDecl.getZChannelNameList(); //Aqui vai retornar uma lista com todos os canais declarados. Ex: [, chan, chan2, chan3, chan4] CircusType circusType; ZNameList declNames = channelDecl.getZChannelNameList(); //By Sam, o de cima modificado Expr expr = channelDecl.getExpr(); //Aqui � o tipo do canal: Ex: |N (naturais) if (!this.bench) this.maxAbsValueComm = exhibitOptionPane4MaxAbsValueComm (expr); else this.maxAbsValueComm = 3; System.out.print(""); this.tse.put("_IntegerType_", this.maxAbsValueComm - this.minComm + 1); for (int i = 0; i < declNames.size(); i++) { //Sam ZName declName = (ZName) declNames.get(i); //Sam this.chanMSEnv.update(declName.toString(), false); //Sam Vector > vv = CCUtil.toVVBigInteger(expr, this.minComm, this.maxAbsValueComm, _env, this.tse); chanTypeEnv.put(declName.toString(), vv); //Sam chanTypeEnv.putType(declName.toString(), expr); chanDimEnv.put (declName.toString(), ExprUtil.sizeOfExpression (expr)); //Sam's AbsCommValuesGenerator acvg = new AbsCommValuesGenerator ("paper", "src", projectDir, specNameOnTranslation, declName.toString(), vv); this.absGens.addElement(acvg); } if (expr != null) { if (genNames != null && genNames.size() > 0) { // Transforms the ListTerm into a list of String List genNamesString = new ArrayList(); for (int i = 0; i < genNames.size(); i++) { genNamesString.add(genNames.get(i).toString()); } circusType = new CircusType(genNamesString, expr); } else { circusType = new CircusType(expr); System.out.print (""); } } else { // Single sync channel circusType = CircusType.createSyncType(); } /* for (int i = 0; i < ((ZNameList)declNames.get(1)).size(); i++) { ZName declName = (ZName) ((ZNameList)declNames.get(1)).get(i); //ACIMA: os get(i) acima s�o cada canal, de chan1, at� chan4 this._env.declareName(declName, NameType.Channel, circusType); } */ for (int i = 0; i < declNames.size(); i++) { ZName declName = (ZName) declNames.get(i); //ACIMA: os get(i) acima s�o cada canal, de chan1, at� chan4 this._env.declareName(declName, NameType.Channel, circusType); } // } else { //Comentado por Samuel // A channel declaration can only be of type VarDecl // This must not happen because the parser must not let this pass; // it's good to check again here anyway. // Note: better to be a invalid format exception //throw new InvalidSubTypeException(decl.getClass()); // } //Comentado por Samuel return null; } /** * */ public Object visitVarDecl(VarDecl varDecl) { //Declara��o de vari�vel em defini��o axiom�tica. //VarDecl [x : SAM] //ListTerm declNames = varDecl.getDeclName(); //By Angela ZNameList declNames = varDecl.getName(); //Nome da vari�vel da declara��o. No caso de exemplo_czt, retorna "x" Expr expr = varDecl.getExpr(); //Retorna SAM // Visits the expression expr.accept(this); // Creates a CircusType CircusType circusType = new CircusType(expr); // Gets the IdType annotation NameType nameType = Util.getAndRemoveNameTypeAnn(varDecl); // Declares each name in the list for (int i = 0; i < declNames.size(); i++) { /*DeclName*/ZName declName = /*(DeclName)*/ (ZName) declNames.get(i); //Sam comment: Acho que aqui, cada get(i) retorna um nome da lista de nomes da declara��o de vari�veis. Para exemplo_czt, aqui retorna x // Declares in the current scope _env.declareName(declName, nameType, circusType); // Add the type annotation Util.addCircusTypeAnn(declName, circusType); } return null; } /** * Returns the signature */ public Object visitConstDecl(ConstDecl constDecl) { //A SER VERIFICADO DEPOIS //JOptionPane.showMessageDialog (null, "Visitou ConstDecl"); /*DeclName*/ZName declName = (ZName) constDecl.getName(); //By Sam, modificado do de cima Expr expr = constDecl.getExpr(); // Visits the expression expr.accept(this); // Creates a circus type CircusType circusType = new CircusType(expr); // Gets the IdType annotation NameType nameType = Util.getAndRemoveNameTypeAnn(constDecl); // Declares in the current scope circusType = this._env.declareName(declName, nameType, circusType); // Add the type annotation Util.addCircusTypeAnn(declName, circusType); return null; } /** ************************************************************************************************************** * Para Tree. * @return null. * *************************************************************************************************************** */ /** * */ public Object visitChannelPara(ChannelPara channelPara) { //Funciona como esperado //ListTerm decls = channelPara.getChannelDecl(); //By Angela ZDeclList decls = (ZDeclList) channelPara.getDeclList(); //Retorna um ZDeclList //By Sam, modified do de cima for (int i = 0; i < decls.size(); i++) { //Decl decl = (Decl) decls.get(i); //By Angela Decl decl = (Decl) decls.get(i); //Retorna um ChannelDeclImpl //By Sam decl.accept(this); } return null; } /** * */ public Object visitChannelSetPara(ChannelSetPara channelSetPara) { //A ser verificado depois!!! //DeclName declName = channelSetPara.getName(); //By Angela!! ZName declName = (ZName) channelSetPara.getName(); //By Sam, modificado do de cima ChannelSet channelSet = channelSetPara.getChannelSet(); Set set = (Set) channelSet.accept(this); //Angela's //CircusChannelSet set = (CircusChannelSet) channelSet.accept(this); //Sam's _env.declareChannelSet(declName.toString(), set); return null; } /** * */ public Object visitProcessPara(ProcessPara processPara) { //DeclName declName = processPara.getName(); //By Angela!! ZName declName = (ZName) processPara.getName(); //Retorna P CircusProcess circusProcess = processPara.getCircusProcess(); this.addProcToProcess1Env (processPara); //By Samuel Barrocas (01/12/2010, 02:09hs da manh�) this.processPara = processPara; //By Samuel Barrocas (09/12/2010, 20:07hs) // Sets the name of the current process _currentProc = declName; // Here we enter in the scope of a process _globalScope = false; // Hiding is permitted only here if (circusProcess instanceof HideProcess) { Util.addHideOkAnn((HideProcess) circusProcess); } this.currentProcessName = declName.toString(); // Visits the process /*if (currentProcessName.equals("Cassino")) { BasicProcess bp = (BasicProcess) circusProcess; ParallelismPrinter.printAction (bp.getMainAction()); }*/ if (declName.toString().equals ("Table")) { System.out.print (""); } ProcChanEnv procChanEnv = (ProcChanEnv) circusProcess.accept(this); this.pn2pce.put(declName.toString(), procChanEnv); //By Samuel Barrocas, 19/12/2010, 06:43hs // Adds the annotation Util.addProcChanEnvAnn (processPara, procChanEnv); /***SAM, 30/11/2010, 03:21hs da manha, a seguir****/ ChanUseEnv chanUseEnvVis = procChanEnv.getChanUseEnvVis(); Iterator iteratorVisible = chanUseEnvVis.iteratorKeys(); iteratorVisible = chanUseEnvVis.iteratorKeys(); while (iteratorVisible.hasNext()) { String channelName = (String) iteratorVisible.next(); ProcChanUseEnv pcuseenv = procChanEnv.getChanInfoEnv().get(channelName); if (procChanEnv.getChanInfoEnv().get(channelName).isMultiSync2(this.pcme.get(declName.toString()))) this.chanMSEnv.update (channelName, true); } /***SAM, 30/11/2010, 03:21hs da manha, acima****/ this.procProcessParaEnv.put(processPara.getZName().toString(), processPara); //By Samuel Barrocas, 16/12/2010, 17:40hs this.p2pId.put(Util.getIdCircusProcessAnn(processPara.getCircusProcess()).getId(), processPara.getZName().toString()); // Adds the annotation Util.addChannelMSEnvAnn(processPara, procChanEnv.getChanInfoEnv()); // TODO: Tirar isto? _env.declareProcess(declName.toString(), procChanEnv); // Here we return to the global scope _globalScope = true; // Sets the name of the current process to null _currentProc = null; return null; } /** * */ public Object visitFreePara(FreePara freePara) { //Este est� Ok, funcionando como esperado ZFreetypeList freeTypes = (ZFreetypeList) freePara.getFreetypeList(); //Retorna ZFreeTypeListImpl for (int i = 0; i < freeTypes.size(); i++) { Freetype freetype = (Freetype) freeTypes.get(i); //Retorna FreeTypeImpl freetype.accept(this); } return null; } /** * */ public Object visitActionPara(ActionPara actionPara) { //Est� Ok, funcionando corretamente ProcChanEnv result = null; mucounter = 0; ZName actionName = (ZName) actionPara.getName(); //Retorna "Action" CircusAction circusAction = actionPara.getCircusAction(); //Retorna PrefixingActionImpl _currentAct = actionName; //JOptionPane.showMessageDialog (null, "EnvLoadingVisitor linha 857: \n\n" + PrinterUtil.printAction(circusAction)); result = (ProcChanEnv) circusAction.accept(this); //if (result instanceof ParAction) //ProcFriendshipEnv.printSetOfSets(((ProcChanEnv)((ParAction)result)).getChanInfoEnv().getFriendship("a")); //actionPara.setCircusAction(ParallelismVisitor.updatedAction (circusAction, processPara.getCircusProcess(), result.getChanInfoEnv().getChanProcFriendshipEnvMap())); _currentAct = null; return result; } public Object visitNameSetPara(NameSetPara NameSetPara) { //N�o precisa verificar return null; } public Object visitAxPara(AxPara axPara) { Box box = axPara.getBox(); NameList genParams = axPara.getNameList(); // not dealing with generics for the moment SchText schText = axPara.getSchText(); //Retorna ZSchTextImpl // Validates the value of box assert(box.equals(Box.AxBox) || box.equals(Box.OmitBox) || box.equals(Box.SchBox)): "box = " + box.toString(); if (box.equals(Box.AxBox) ) { // Axiomatic or horizontal definition NameType nameType; if (this._globalScope) { nameType = NameType.GlobalConstant; } else { nameType = NameType.LocalConstant; } ZDeclList decls = (ZDeclList)((ZSchText) schText).getDeclList(); Pred pred = ((ZSchText) schText).getPred(); _env.openScope(); for (int i=0; i * *************************************************************************************************************** */ /** * */ //public Object visitBasicChannelSet(/*BasicChannelSet*/BasicChannelSetExpr basicChannelSet) { //Ainda a ser verificado public Object visitChannelSet(/*BasicChannelSet*/ChannelSet basicChannelSet) { //Ainda a ser verificado Set r = new LinkedHashSet(); //ListTerm list = basicChannelSet.getRefName(); //Angela's CircusCommunicationList list; ZName refName; if (((CircusChannelSet)basicChannelSet).getExpr() instanceof RefExpr) { //IMPORTANTE: O conte�do desse if corresponde ao conte�do do visitador visitRefChannelSet, no JCircus de Angela refName = (ZName)(/*(BasicChannelSetExpr)*/ (RefExpr)( (CircusChannelSet)basicChannelSet).getExpr() ).getName(); //Checar esse cara depois Set result = null; result = this._env.getChannelSet(refName.toString()); return result; } else { //O conte�do deste bloco � o corresponde ao conte�do do visitador visitBasicChannelSet,no JCircus de Angela list = (CircusCommunicationList)((BasicChannelSetExpr)( (CircusChannelSet)basicChannelSet).getExpr() ).getCommunicationList(); //Checar esse cara depois for (int i = 0; i < list.size(); i++) { r.add(list.get(i).toString()); } return r; } } /** * */ //public Object visitRefChannelSet (/*RefChannelSet*/ChannelSet refChannelSet) { //visitChannelSet, na verdade, vai substituir visitBasicChannelSet!!!!! public Object visitBasicChannelSetExpr (/*RefChannelSet*/BasicChannelSetExpr refChannelSet) { //Ainda a ser verificado //Com T_ActMod, nao da para testar esse, pois nao passa por aqui Set result = null; //RefName refName = refChannelSet.getRefName(); //Angela's ZName refName = ((ChannelSetPara) refChannelSet).getZName(); //Sam's result = this._env.getChannelSet(refName.toString()); return result; } /** ************************************************************************************************************** * NameSet Tree. * *************************************************************************************************************** */ /** ************************************************************************************************************** * CircusProcess Tree. * *************************************************************************************************************** */ /** * The methods of these tree always return a ProcessChannelEnvironment. */ /** * */ /*public ActionParaImpl getMainAction (BasicProcess bp) { Para mainAction; ZParaList paras = bp.getZParaList(); for (int i = 0; i < paras.size(); i++) { if (((Para)paras.get(i)).) } }*/ public Object visitBasicProcess(BasicProcess basicProcess) { this.mucounter = 0; ProcChanEnv result = new ProcChanEnv(); ZName stateSchemaRefName = null; AxPara statePara = basicProcess.getStatePara(); //AxParaImpl if (statePara != null) { ZSchText stateText = statePara.getZSchText(); ZDeclList stateVars = stateText.getZDeclList(); Decl declOfState = stateVars.get(0); if (declOfState instanceof VarDecl) { ZNameList namesAtState = ((VarDecl)declOfState).getZNameList(); stateSchemaRefName = (ZName) namesAtState.get(0); } else {//if (declOfState instanceof ConstDecl) { ZName nameAtState = ((ConstDecl)declOfState).getZName(); stateSchemaRefName = nameAtState; } } CircusAction mainAction = basicProcess.getMainAction(); //Angela's ZParaList actionParas = basicProcess.getZParaList(); //Angela's ZParaList zParas = basicProcess.getZParaList(); //ZName stateSchemaRefName = (ZName) ((ConstDecl)((ZSchText) basicProcess.getStatePara().getSchText()).getZDeclList().get(0)).getName(); //try { // Set global variable if (stateSchemaRefName != null) { _stateName = stateSchemaRefName.toString(); } // Visit the zParas for (int i = 0; i < zParas.size(); i++) { //Acrescentado o CAST ZParaList if (zParas.get(i) instanceof AxPara || zParas.get(i) instanceof FreePara) { Para para = (Para) zParas.get(i); //Acrescentado o CAST ZParaList para.accept(this); System.out.print (""); } } // Visit the nameSetParas /*for (int i = 0; i < nameSetParas.size(); i++) { NameSetPara nameSetPara = (NameSetPara) nameSetParas.get(i); //Angela's nameSetPara.accept(this); }*/ if (stateSchemaRefName != null && !stateSchemaRefName.toString().contains ("$$defaultSt")) { // This process defines a state // Inserts type annotation in the state CircusType circusType = this._env.getCircusType(stateSchemaRefName.toString()); Util.addCircusTypeAnn(stateSchemaRefName, circusType); // Brings all the declarations in the state to this scope (the type //of the state will always be a signature (schema type)) Signature signature = null; //if (circusType != null) signature = ((SignatureExpression) circusType.getExpression()).getSignature(); this.defineSignature(signature, NameType.StateComponent); //DESCOMENTAR }//*/ ProcChanEnv procChanEnv = null; // Visits the circusActions for (int i = 0; i < ((ZParaList) actionParas).size() - 1; i++) { //acrescentei o CAST e o -1 if ((actionParas.get(i) instanceof ActionPara)/* && nao � a acao principal, de circspot*/) { System.out.print(""); ActionPara actionPara = (ActionPara) ((ZParaList) actionParas).get(i); //Acrescentei o CAST de ZParaList CircusAction circusAction = actionPara.getCircusAction(); // Visits the circus action only if it is not the state procChanEnv = (ProcChanEnv) actionPara.accept(this); result = result.merge(procChanEnv, false, new Vector ()); } } // Visits the main action procChanEnv = (ProcChanEnv) mainAction.accept(this); result = result.merge(procChanEnv, false, new Vector ()); // Add id annotation int id = IdCircusProcessGenerator.getGenerator().getNextId(); IdCircusProcessAnn ann = new IdCircusProcessAnn(id); Util.addIdCircusProcessAnn(basicProcess, ann); // Updates MultiSyncEnv result.transform(new Integer (id), this.currentProcessName); //Comentado por Samuel em 06/05/2013 // Set the flag to say that this is a environment for a basic process result.setBasicProcess(); //} /*catch (MoreThanOneWriterException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.PAR_WRITERS, params), e); } catch (ChanUseUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANUSE_UNIF, params), e); } catch (DifferentCardinalitiesException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.DIFF_CARD, params), e); } catch (ChanSyncUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANSYNC_UNIF, params), e); } */ // Set global variable _stateName = null; return result; } /** * */ public Object visitCallProcess(CallProcess callProcess) { ProcChanEnv result = null; //CallProcess c = null; //c.getCallExpr(); //RefName refName = callProcess.getRefName(); //Angela's //CallType callType = callProcess.getCallType(); //Angela's Name refName = callProcess.getCallExpr().getName(); //Sam's CallUsage callType = callProcess.getUsage(); //Parameterised // Validate the value of callType // assert(callType == CallType.Param || callType == CallType.Gen || //Daqui pra baixo tudo Angela's, at� o �ltimo comentado // callType == CallType.Index || callType == CallType.Normal): // "callType = " + callType.toString(); // if (callType == CallType.Normal) { assert(callType == CallUsage.Parameterised || //Daqui pra baixo ate o correspondente de cima, Sam's callType == CallUsage.Indexed ): "callType = " + callType.toString(); if (callType == CallUsage.Parameterised) { //Sam's, correspondente ao CallType.Normal // Gets the environment of the process // Is this really necessary? A CallProcess will be translated as another process ... result = this._env.getProcessChannelEnvironment(refName.toString()); //} else if (callType == CallType.Param || callType == CallType.Gen || callType == CallType.Index) { //Angela's } else { //Sam's // ListTerm params = callProcess.getExprList(); //Angela's ListTerm params = (ListTerm) ((RefExpr) callProcess).getExprList(); //Sam's // Visit the parameters for (int i = 0; i < params.size(); i++) { Expr expr = (Expr) params.get(i); expr.accept(this); } // Gets the environment of the process result = this._env.getProcessChannelEnvironment(refName.toString()); } // Add id annotation IdCircusProcessAnn ann = new IdCircusProcessAnn(IdCircusProcessGenerator.getGenerator().getNextId()); Util.addIdCircusProcessAnn(callProcess, ann); //this.procProcessParaEnv.put(Util.getIdCircusProcessAnn(processPara.getCircusProcess()).getId(), processPara.getCircusProcess()); //By Samuel Barrocas, 16/12/2010, 17:40hs this.p2pId.put(ann.getId(), callProcess.getCallExpr().getZName().toString()); if (result.isBasicProcess() /*&& callProcess.getAnn(CopyProcessAnn.class) != null*/) { // If this is a call to a basic process, I need to substitute the ids // of the basic process in ChanSyncEnv by the ids of this callProcess /** Isto estava errado! MultiSyncEnv multiSyncEnv = result.getMultiSyncEnv(); multiSyncEnv = multiSyncEnv.replaceId(ann.getId()); result.setMultiSyncEnv(multiSyncEnv); */ result = result.replaceIdInChanInfoEnv(ann.getId(), refName.toString()); } return result; } /** * */ public Object visitProcess1(Process1 process1) { ProcChanEnv result; CircusProcess circusProcess = process1.getCircusProcess(); result = (ProcChanEnv) circusProcess.accept(this); // Add id annotation IdCircusProcessAnn ann = new IdCircusProcessAnn( IdCircusProcessGenerator.getGenerator().getNextId()); Util.addIdCircusProcessAnn(process1, ann); return result; } /** * */ public Object visitRenameProcess(RenameProcess renameProcess) { ProcChanEnv result = null; //Com T_Act.tex, n�o pode ser testado CircusProcess circusProcess = renameProcess.getCircusProcess(); //ListTerm oldChannels = renameProcess.getOldNames(); //Angela's //ListTerm newChannels = renameProcess.getNewNames(); //Angela's ZNameList oldChannels = (ZNameList) renameProcess.getAssignmentPairs().getLHS(); //By Sam, mas ainda falta modificar!!! ZExprList newChannels = (ZExprList) renameProcess.getAssignmentPairs().getRHS(); //By Sam, mas ainda falta modificar!!! result = (ProcChanEnv) circusProcess.accept(this); result = result.substitute(newChannels, oldChannels); // Add id annotation IdCircusProcessAnn ann = new IdCircusProcessAnn( IdCircusProcessGenerator.getGenerator().getNextId()); Util.addIdCircusProcessAnn(renameProcess, ann); return result; } /** * */ public Object visitHideProcess(HideProcess hideProcess) { ProcChanEnv result = null; CircusProcess circusProcess = hideProcess.getCircusProcess(); ChannelSet channelSet = hideProcess.getChannelSet(); // Check if this hiding is legal if (Util.getHideOkAnn(hideProcess) == null) { Object[] params = new Object[] { _currentProc }; reportError(new Error(ErrorMessage.HIDE_PROC_ILLEGAL, params)); } Set channelNames = (Set) channelSet.accept(this); result = (ProcChanEnv) circusProcess.accept(this); result = result.hide(channelNames); // Add id annotation IdCircusProcessAnn ann = new IdCircusProcessAnn( IdCircusProcessGenerator.getGenerator().getNextId()); Util.addIdCircusProcessAnn(hideProcess, ann); this.alreadyDefinedId = false; return result; } /** * */ public Object visitProcessD(ProcessD processD) { ProcChanEnv result; //Com T_ActMod, nao pode ser testado //ListTerm decls = processD.getDecl(); //By Angela ZDeclList decls = (ZDeclList) processD.getDeclList(); //By Sam CircusProcess circusProcess = processD.getCircusProcess(); NameType nameType; if (processD instanceof ProcessIte || processD instanceof ProcessIdx) { // TODO: Think about the NameType in this case. nameType = NameType.LocalVariable; } else if (processD instanceof ParamProcess) { nameType = NameType.ProcessParam; } else { throw new InvalidSubTypeException(processD.getClass()); } // Open a new scope to declare the block of variables _env.openScope(); for (int i = 0; i < decls.size(); i++) { Decl decl = (Decl) decls.get(i); // Add IdType annotation to the declaration Util.addNameTypeAnn(decl, nameType); //if (((VarDecl)decl).getName().get(0).toString().equals("ident")) { //System.out.print(""); //} // Visits the declaration decl.accept(this); } result = (ProcChanEnv) circusProcess.accept(this); // Close scope _env.closeScope(); // Add id annotation /*IdCircusProcessAnn ann = new IdCircusProcessAnn( IdCircusProcessGenerator.getGenerator().getNextId());*/ Util.addIdCircusProcessAnn(processD, Util.getIdCircusProcessAnn(processD.getCircusBasicProcess())/*ann*/); this.alreadyDefinedId = false; return result; } /** * * @param process2 * @return */ public Object visitProcess2(Process2 process2) { ProcChanEnv result = null; ProcChanEnv procChanLeft = (ProcChanEnv) process2.getLeftProcess().accept(this); //By Sam, modified do de cima ProcChanEnv procChanRight = (ProcChanEnv) process2.getRightProcess().accept(this); //By Sam, modified do de cima result = procChanLeft.merge(procChanRight, false, new Vector ()); // Add id annotation IdCircusProcessAnn ann = new IdCircusProcessAnn( IdCircusProcessGenerator.getGenerator().getNextId()); Util.addIdCircusProcessAnn(process2, ann); return result; } /** * Special case for parallelism */ public Object visitParProcess(ParProcess parProcess) { ProcChanEnv result = null; IdCircusProcessAnn ann; ProcChanEnv procChanLeft = (ProcChanEnv) parProcess.getLeftProcess().accept(this); ProcChanEnv procChanRight = (ProcChanEnv) parProcess.getRightProcess().accept(this); //procChanLeft.setChannelSet(InterleavingVisitor.channelSet(parProcess)); //By Samuel Barrocas //procChanRight.setChannelSet(InterleavingVisitor.channelSet(parProcess)); //By Samuel Barrocas Vector chanSet = ChanSetUtil.channelSet(parProcess, this.spec); //Samuel Barrocas result = procChanLeft.merge(procChanRight, true, chanSet); result.setChannelSet (ChanSetUtil.channelSet(parProcess, this.spec)); //By Samuel Barrocas // Add id annotation ann = new IdCircusProcessAnn( IdCircusProcessGenerator.getGenerator().getNextId() ); Util.addIdCircusProcessAnn(parProcess, ann); this.cp2cse.put(Util.getIdCircusProcessAnn (parProcess.getLeftProcess()).getId(), ChanSetUtil.channelSet(parProcess, this.spec)); this.cp2cse.put(Util.getIdCircusProcessAnn (parProcess.getRightProcess()).getId(), ChanSetUtil.channelSet(parProcess, this.spec)); System.out.print(""); //} /*catch (MoreThanOneWriterException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.PAR_WRITERS, params), e); } catch (ChanUseUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANUSE_UNIF, params), e); } catch (ChanSyncUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANSYNC_UNIF, params), e); } catch (DifferentCardinalitiesException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.DIFF_CARD, params), e); }*/ return result; } /** ************************************************************************************************************** * CircusAction Tree. * *************************************************************************************************************** */ /** * */ public Object visitBasicAction(BasicAction basicAction) { return new ProcChanEnv(); } /** * */ public Object visitAction1(Action1 action1) { ProcChanEnv result; CircusAction circusAction = action1.getCircusAction(); result = (ProcChanEnv) circusAction.accept(this); return result; } /** * */ private int countParams (NameTypeEnv nameTypeEnv) { //Samuel, 12/09/2013 StringBuilder code = new StringBuilder(); //Iterator keys = nameTypeEnv.iteratorKeys(); //Angela's Iterator keys = nameTypeEnv.iteratorKeys(); //Sam's String comma = ""; int counter = 0; while (keys.hasNext()) { ZName declName = keys.next(); //Sam's NameType nameType = (NameType) declName.getAnn(NameType.class); if (nameType.equals( NameType.LocalVariable) || nameType.equals( NameType.ActionParam)) { CircusType circusType = nameTypeEnv.getCircusType(declName.toString()); // Code for declaration of parameter counter++; } } return counter; } public void putParamSizeOnMu (String muname, NameTypeEnv localenv) { int nparams = countParams (localenv); this._muActs2Indexes.putnparams(this.currentProcessName, muname, nparams); } public Object visitMuAction (MuAction muAction) { /* RecursiveAction */ ProcChanEnv result = null; //DeclName declName = muAction.getName(); //By Angela ZName declName = (ZName) muAction.getName(); //By Sam, modificado do de cima NameTypeEnv localEnvironment = this._env.localEnvironment(); CircusAction circusAction = muAction.getCircusAction(); // Add annotation Util.addNameTypeEnvAnn(muAction, localEnvironment); if (!this._muActs2Indexes.containsKey(this.currentProcessName, declName.toString())) { this._muActs2Indexes.putmu(this.currentProcessName, declName.toString(), mucounter); putParamSizeOnMu (declName.toString(), localEnvironment); mucounter++; } // Open scope for what ? Declaration of DeclName possibly. _env.openScope(); result = (ProcChanEnv) circusAction.accept(this); // Close scope _env.closeScope(); return result; } /** * */ public Object visitActionD(ActionD actionD) { ProcChanEnv result = null; //ListTerm decls = actionD.getDeclList(); //Original, da Angela ZDeclList decls = (ZDeclList) actionD.getDeclList(); //By Sam, modificado do de cima CircusAction circusAction = actionD.getCircusAction(); // Add annotation of local environment NameTypeEnv localEnvironment = this._env.localEnvironment(); Util.addNameTypeEnvAnn(actionD, localEnvironment); NameType nameType; if (actionD instanceof ActionIte) { nameType = NameType.LocalVariable; //? } else if (actionD instanceof ParamAction) { nameType = NameType.ActionParam; } else { throw new InvalidSubTypeException(actionD.getClass()); } // Open scope _env.openScope(); for (int i = 0; i < decls.size(); i++) { Decl decl = (Decl) decls.get(i); // Adds the annotation Util.addNameTypeAnn(decl, nameType); // Visits the declaration decl.accept(this); //this.environment_.declareInCurrentScope(decl, nameType); } result = (ProcChanEnv) circusAction.accept(this); // Close scope _env.closeScope(); return result; } /** * */ public Object visitGuardedAction(GuardedAction guardedAction) { ProcChanEnv result = null; Pred pred = guardedAction.getPred(); CircusAction circusAction = guardedAction.getCircusAction(); pred.accept(this); result = (ProcChanEnv) circusAction.accept(this); return result; } /** * */ public Object visitAction2(Action2 action2) { ProcChanEnv result = new ProcChanEnv(); result = (ProcChanEnv) action2.getLeftAction().accept(this); //try { result = result.merge((ProcChanEnv) action2.getRightAction().accept(this), false, new Vector ()); //} /*catch (MoreThanOneWriterException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.PAR_WRITERS, params), e); } catch (ChanUseUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANUSE_UNIF, params), e); } catch (ChanSyncUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANSYNC_UNIF, params), e); } catch (DifferentCardinalitiesException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.DIFF_CARD, params), e); }*/ return result; } /** * */ //OS M�TODOS ABAIXO FORAM ORIGINALMENTE IMPLEMENTADOS PELA ANGELA FREITAS, MAS APENAS EM TranslatorVisitor. //OS COPIEI E COLEI AQUI PARA AUXILIAR NA CONSTRUCAO DE ChanExtChoiceEnv, no visitador de ExtChoiceAction private String initialChannelFromAction(CircusAction circusAction) { String code = ""; // TODO: the rest of the types of CircusActions, including RefName // (create an action environment, to getCircusType the // Action from its declName) if (circusAction instanceof GuardedAction) { // Recursive case code = initialChannelFromAction(((GuardedAction) circusAction).getCircusAction()); } else if (circusAction instanceof PrefixingAction) { // Base case Communication communication = ((PrefixingAction) circusAction).getCommunication(); // Code for channel //code = communication.getChanName().toString(); //angela code = communication.getChannelExpr().getZName().toString(); //sam } /*else if (circusAction instanceof ExtChoiceAction) { }*/ else { System.out.println (PrinterUtil.printAction (circusAction, spec)); // Error Object[] params = new Object[] { _currentProc, _currentAct }; reportError(new Error(ErrorMessage.EXTCH_BRANCH, params)); } return code; } private List initialChannelsFromActionList(List actions) { List result = new ArrayList(); for (int i = 0; i < actions.size(); i++) { CircusAction circusAction = actions.get(i); String channelName = initialChannelFromAction(circusAction); result.add(channelName); } return result; } //////////////////////////////////////////////////////////////////////////////////// public Object visitExtChoiceAction(ExtChoiceAction extChoiceAction) { // Special case. Need to classify the channels as alting channel input ProcChanEnv result = new ProcChanEnv(); extChoiceAction = (ExtChoiceAction) ChoiceUtil.replaceGuardsOnExtChoice(extChoiceAction); CircusAction leftAction = extChoiceAction.getLeftAction(); CircusAction rightAction = extChoiceAction.getRightAction(); if (!(leftAction instanceof ExtChoiceAction) && !(leftAction instanceof PrefixingAction)) { if (!(rightAction instanceof ExtChoiceAction) && !(rightAction instanceof PrefixingAction)) { System.out.print (""); } } List actions = Util.getActions(extChoiceAction, Constants.OP_EXTCHOICE); List channels = this.initialChannelsFromActionList(actions); //Sam's for (int i = 0; i < channels.size(); i++) { String channelName = channels.get(i); this.cece.update(channelName, true); } for (int i = 0; i < actions.size(); i++) { CircusAction circusAction = (CircusAction) actions.get(i); // Sets the flag for external choice _extChoice = true; //try { result = result.merge((ProcChanEnv) circusAction.accept(this), false, new Vector ()); //} /*catch (MoreThanOneWriterException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.PAR_WRITERS, params), e); } catch (ChanUseUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.CHANUSE_UNIF, params), e); } catch (ChanSyncUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANSYNC_UNIF, params), e); } catch (DifferentCardinalitiesException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.DIFF_CARD, params), e); }*/ } return result; } /** * */ public Object visitParAction(ParAction parAction) { ProcChanEnv result = new ProcChanEnv(), result2 = new ProcChanEnv (); Vector chanSet = ChanSetUtil.channelSet(parAction, this.spec); //HashMap mapChanProcFriendshipEnv = ChanInfoEnv.mergeFriendshipBottomUp(parAction, chanSet, this); // Add annotation NameTypeEnv localEnvironment = this._env.localEnvironment(); Util.addNameTypeEnvAnn(parAction, localEnvironment); result = (ProcChanEnv) parAction.getLeftAction().accept(this); result2 = (ProcChanEnv) parAction.getRightAction().accept(this); result = result.merge ( result2 /*(ProcChanEnv) parAction.getRightAction().accept(this)*/, true, chanSet); //try { //result = result.merge((ProcChanEnv) parAction.getRightAction().accept(this), true); //} /*catch (MoreThanOneWriterException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.PAR_WRITERS, params), e); } catch (ChanUseUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANUSE_UNIF, params), e); } catch (ChanSyncUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANSYNC_UNIF, params), e); } catch (DifferentCardinalitiesException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.DIFF_CARD, params), e); }*/ return result; } /** * */ //public Object visitCallAction(CallAction callAction) { //Angela's public Object visitCallAction(CallAction callAction) { ProcChanEnv result = new ProcChanEnv(); //RefName refName = callAction.getRefName(); //By Angela //CallType callType = callAction.getCallType(); //By Angela ZName refName = callAction.getZName(); //By Sam, modificado do de cima //CallUsage callType = callAction. //By Sam, COMENTADO // Validate the value of callType //assert(callType == CallType.Param || callType == CallType.Gen || //Angela's // assert(callType == CallUsage.Parameterised ||//Sam's //callType == CallType.Index || callType == CallType.Normal): //Angela's // callType == CallUsage.Indexed) : //Sam's // "callType = " + callType.toString(); //if (callType == CallType.Normal) { //Angela's // if (callType != CallUsage.Parameterised && //Sam's, essa e as pr�ximas 3 linhas!!!!!!!! // callType != CallUsage.Indexed) { //Sam's // Nothing to be done here. // The RefName is a reference to another action (in this same // process) which has already been visited or will be visited. // This name can be a name of an action or a recursive call // TODO: Check if this should be annotated as NameType.RecursiveName ? //Util.addNameTypeAnn(refName, NameType.ActionName); // } else if (callType == CallType.Param || //Daqui para baixo, at� o que t� comentado, � Angela's // callType == CallType.Gen || callType == CallType.Index) { // // ListTerm params = callAction.getExprList(); // Expr expr; // } else { //Sam's ZExprList params = (ZExprList) callAction.getExprList(); //Sam's Expr expr; //Sam's // Visit the parameters for (int i = 0; i < params.size(); i++) { expr = (Expr) params.get(i); expr.accept(this); } // This name can be a name of an action or a recursive call // TODO: Check if this should be annotated as NameType.RecursiveName ? Util.addNameTypeAnn(refName, NameType.ActionName); //} return result; } /** * */ int counterHash = 0; public Object visitPrefixingAction(PrefixingAction prefixingAction) { ProcChanEnv result = null; CircusAction circusAction = prefixingAction.getCircusAction(); Communication communication = prefixingAction.getCommunication(); // Open scope for the possible declaration of input variable // ATTENTION: Originally, this was done before the visitation of the fields. _env.openScope(); // Visits the communication communication.accept(this); ChanUse chanUse = ChanUse.Undefined; ChanSync chanSync = ChanSync.C; try { chanUse = Util.getChanUseClassification(communication); // Finds out the classification (ChanUse and ChanSync) of communication if (this._extChoice) { if (chanUse.equals(ChanUse.Output)) { Object[] params = new Object[] { _currentProc, _currentAct, communication./*getChanName()*/getChannelExpr().getName() }; if (!useBarriers) { reportFatalError(new Error(ErrorMessage.OUTPUT_EXT_CHOICE, params)); } } chanUse = ChanUse.Input; this._extChoice = false; } else { chanUse = Util.getChanUseClassification(communication); } chanSync = Util.getChanSyncClassification(communication); } catch (InvalidFormatCommException e) { Object[] params = new Object[] { _currentProc, _currentAct, communication./*getChanName()*/getChannelExpr().getName() }; if (!useBarriers || !ChanComplexCommEnv.isComplexComm(communication)) reportFatalError(new Error(ErrorMessage.CHAN_FORMAT, params), e); } // Includes as a visible channel // (Gets the type of the channel in the environment) CircusType circusTypeChannel = this._env.getCircusType( communication./*getChanName()*/getChannelExpr().getName().toString()); // Visits the action result = (ProcChanEnv) circusAction.accept(this); /*Daqui para baixo, @author: Samuel Lincoln M. Barrocas*/ HashSet hs = new HashSet (); hs.add(counterHash /*prefixingAction.hashCode()*/); //OBS: Usar o hashCode n�o est� dando certo... Parece que todas as a��es prefixadas t�m o mesmo c�digo hash!! //this.pa2ie.put(counterHash, prefixingAction); prefixingAction.getAnns().add(new Integer (counterHash)); counterHash++; //ProcFriendshipEnv pfe = new ProcFriendshipEnv (hs); //HashMap map = new HashMap (); //map.put(communication.getChannelExpr().getName().toString(), pfe); //result.setChanInfoEnv (new ChanInfoEnv ()); //result.getChanInfoEnv().setChanProcFriendshipEnvMap(map); //System.out.println (); /*Daqui para cima, @author: Samuel Lincoln M. Barrocas*/ // Closes the scope _env.closeScope(); try { result.includeVisible(communication./*getChanName()*/getChannelExpr().getName().toString(), chanUse, chanSync, circusTypeChannel); System.out.println ("includeVisible"); } catch (ChanDefOtherChanUseException e) { System.out.println ("ChanDefOtherUse"); } catch (ChanDefOtherChanSyncException e) { System.out.println ("ChanDefOtherSync"); } return result; } /** * */ public Object visitCommunication(Communication communication) { // When the integration with the typechecker is done, it will // not be necessary to add information about circus type only // name type. this.chanDotFieldEnv.put(communication); ZName chanName = (ZName) communication.getChannelExpr().getName(); //Sam's if (ChanComplexCommEnv.isComplexComm(communication)) { //Sam's this.ccce.update(chanName.toString(), true); } CircusFieldList chanFields = communication.getCircusFieldList(); //Sam's ZExprList genActuals = communication.getChannelExpr().getZExprList(); //Sam's BigInteger multiSych = communication.getMultiSych(); //Sam's CommPattern commType = communication.getCommPattern(); //Sam's // Gets the type of the channel in the environment CircusType circusTypeChannel = this._env.getCircusType(chanName.toString()); // Visits all the fields for (int i = 0; i < chanFields.size(); i++) { Field field = (Field) chanFields.get(i); field.accept(this); } int size = chanFields.size(); //this.chanDimEnv.put (chanName.toString(), chanFields.size()); //Sam's System.out.print(""); // MOVED TO PREFIXING_ACTION // Open scope for the possible declaration of input variable // this.environment_.openScope(); // Gets the last parameter if (chanFields.size() > 0) { Field field = (Field) chanFields.get(chanFields.size()-1); if (field instanceof InputField) { //RefName refName = ((InputField) field).getVariable(); //Angela's ZName refName = ((InputField) field).getVariableZName(); //Sam's // Add a type annotation to the input variable CircusType circusTypeVariable = Util.getLastTypeChannel( circusTypeChannel, /*(ListTerm)*/genActuals); //Acrescentado o cast ListTerm circusTypeVariable = this._env.declareName( //this._factory.createDeclName(refName.toString()), //Angela's this._factory.createZName(refName.toString()), //Sam's NameType.LocalVariable, circusTypeVariable); Util.addCircusTypeAnn(refName, circusTypeVariable); if (chanName.toString().equals ("out")) { System.out.print (""); } } } return null; } /** ************************************************************************************************************** * Field Tree. * *************************************************************************************************************** */ /** * */ public Object visitInputField(InputField inputField) { Pred restriction = inputField.getRestriction(); //RefName variable = inputField.getVariableName(); //Angela's ZName variable = (ZName) inputField.getVariableName(); //Sam's /** * Declaration of the variable will not be done here. * * Instead, it is being done in visit (PrefixingAction), since only * the last input variable needs to be visited (format requirement). */ // variable.addAnn(NameType.LocalVariable); // this.environment_.declareName(new Name( // variable.getName()), NameType.LocalVariable, circusTypeChannel); if (restriction != null) { restriction.accept(this); } return null; } /** * */ // public Object visitOutputField(OutputField outputField) { //Angela's public Object visitOutputField(OutputFieldAnn outputField) { //Sam's //N�o passa por aqui por T_ActMod.tex //Expr expr = outputField.getExpression(); //Angela's Expr expr = ((CircusType) outputField).getExpression(); //Sam's expr.accept(this); return null; } /** * */ public Object visitDotField(DotField dotField) { //Expr expr = dotField.getExpression(); //Angela's Expr expr = dotField.getExpr(); //Sam's expr.accept(this); return null; } /** ************************************************************************************************************** * Command Tree. * *************************************************************************************************************** */ /** * */ public Object visitAssignmentCommand(AssignmentCommand assignmentCommand) { ProcChanEnv result = new ProcChanEnv(); /** * This is result of a change in the AST. No more assignment pairs * (see Manuela's email 13/08/2005 * - Circus.xsd e CircusTools.xsd) */ ZNameList leftVars = (ZNameList) assignmentCommand.getAssignmentPairs().getLHS(); //Sam's ZExprList exprs = (ZExprList) assignmentCommand.getAssignmentPairs().getRHS(); //Sam's for (int i = 0; i < leftVars.size(); i++) { //assignPair = (AssignmentPair) assignmentPairs.get(i); //RefName refName = (RefName) leftVars.get(i); //assignPair.getLHS(); //Angela's ZName refName = (ZName) leftVars.get(i); //Sam's Expr expr = (Expr) exprs.get(i); //assignPair.getRHS(); CircusType circusType = this._env.getCircusType(refName.toString()); // Add annotation of type to the variable Util.addCircusTypeAnn(refName, circusType); // Visits the expression expr.accept(this); } return result; } /** * */ public Object visitIfGuardedCommand(IfGuardedCommand ifGuardedCommand) { ProcChanEnv result = new ProcChanEnv(); //ListTerm guardedActions = ifGuardedCommand.getGuardedAction(); //Angela's CircusActionList guardedActions = (CircusActionList) ifGuardedCommand.getActionList(); //Sam's for (int i = 0; i < guardedActions.size(); i++) { GuardedAction guardedAction = (GuardedAction) guardedActions.get(i); // Visits the guarded action ProcChanEnv procChanEnv = (ProcChanEnv) guardedAction.accept(this); //try { result = result.merge(procChanEnv, false, new Vector ()); //} /*catch (MoreThanOneWriterException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.PAR_WRITERS, params), e); } catch (ChanUseUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANUSE_UNIF, params), e); } catch (ChanSyncUnificationException e) { Object[] params = new Object[] { _currentProc, _currentAct }; if (!useBarriers) reportFatalError(new Error(ErrorMessage.CHANSYNC_UNIF, params), e); } catch (DifferentCardinalitiesException e) { Object[] params = new Object[] { _currentProc, _currentAct }; reportFatalError(new Error(ErrorMessage.DIFF_CARD, params), e); }*/ } return result; } /** * */ public Object visitVarDeclCommand(VarDeclCommand varDeclCommand) { ProcChanEnv result = new ProcChanEnv(); //ListTerm decls = varDeclCommand.getDeclarations(); //Angela's ZDeclList decls = (ZDeclList) varDeclCommand.getDeclList(); //Sam's CircusAction circusAction = varDeclCommand.getCircusAction(); // Open a new scope for block of variables: _env.openScope(); int size; if (decls == null) { System.out.print (""); } if (decls != null) size = decls.size(); else size = 0; for (int i = 0; i < size; i++) { Decl decl = (Decl) decls.get(i); // Adds the annotation Util.addNameTypeAnn(decl, NameType.LocalVariable); DeclUtil.addNameTypeAnnToLocalVariablesOnDecl (decl, this._env); // Visits decl.accept(this); } result = (ProcChanEnv) circusAction.accept(this); // Close scope _env.closeScope(); return result; } /** ************************************************************************************************************** * Pred Tree. * *************************************************************************************************************** */ /** * OK * @param pred * @return */ public Object visitFact(Fact fact) { return null; } public Object visitExprPred(ExprPred exprPred) { Expr expr = exprPred.getExpr(); expr.accept(this); return null; } public Object visitMemPred(MemPred memPred) { Expr leftExpr = memPred.getLeftExpr(); Expr rightExpr = memPred.getRightExpr(); leftExpr.accept(this); rightExpr.accept(this); return null; } /** * */ public Object visitNegPred(NegPred negPred) { negPred.getPred().accept(this); return null; } /** * */ public Object visitPred2(Pred2 pred2) { pred2.getLeftPred().accept(this); pred2.getRightPred().accept(this); return null; } /** ************************************************************************************************************** * Expr Tree. * *************************************************************************************************************** */ /** * */ public Object visitRefExpr(RefExpr refExpr) { //RefName refName = refExpr.getRefName(); //Angela's ZName refName = refExpr.getZName(); //Sam's System.out.println ("________________\n" + refName.toString()); CircusType circusType; if (refName.toString().equals("True")) { circusType = this._env.getCircusType("true"); //Util.addCircusTypeAnn(refName, circusType); } else if (refName.toString().equals("False")) { circusType = this._env.getCircusType("false"); //Util.addCircusTypeAnn(refName, circusType); } else { circusType = this._env.getCircusType(refName.toString()); } //circusType = this._env.getCircusType(refName.toString()); Util.addCircusTypeAnn(refName, circusType); // Gets the name type annotation in the environment and inserts an annotation NameType nameType; if (this._env.getScopeStack().getNameType(refName.toString()) != null) nameType = this._env.getNameType(refName.toString()); else if (this._env.isElementFreeType(refName)) { nameType = NameType.ElemFreeType; } else{ nameType = NameType.ProcessParam; } Util.addNameTypeAnn(refName, nameType); return null; } /** * */ public Object visitNumExpr(NumExpr NumExpr) { return null; } /** * */ public Object visitExpr2(Expr2 expr2) { expr2.getLeftExpr().accept(this); expr2.getRightExpr().accept(this); return null; } /** * */ public Object visitExpr1(Expr1 expr1) { expr1.getExpr().accept(this); return null; } /** * */ public Object visitExpr0N(Expr0N expr0N) { //ListTerm exprs = expr0N.getExpr(); //Angela's ZExprList exprs = (ZExprList) expr0N.getExprList(); //Sam's for (int i = 0; i < exprs.size(); i++) { Expr expr = (Expr) exprs.get(i); expr.accept(this); } return null; } /** * */ public Object visitBindExpr(BindExpr bindExpr) { //ListTerm/**/ pairs = bindExpr.getNameExprPair(); //Angela's ListTerm pairs = (ListTerm) bindExpr.getZDeclList(); //VER DEPOIS COMO FAZER ESSE!!!!!!!!! for (int i = 0; i < pairs.size(); i++) { //NameExprPair pair = (NameExprPair) pairs.get(i); //Angela's //DeclName declName = pair.getName(); //Angela's RefExpr pair = (RefExpr) pairs.get(i); //Sam's VER DEPOIS COMO FAZER ESSE!!!!!! ZName declName = (ZName) pair.getName(); //Sam's, fiz essa troca mas n�o sei se � assim! //Expr expr = pair.getExpr(); //Angela's Expr expr = (Expr) pair.getZExprList(); //Sam's, vamos ver como faz // TODO: annotate the name // Visits the expr expr.accept(this); } return null; } /** * */ public Object visitCondExpr(CondExpr condExpr) { Pred pred = condExpr.getPred(); Expr leftExpr = condExpr.getLeftExpr(); Expr rightExpr = condExpr.getRightExpr(); pred.accept(this); leftExpr.accept(this); rightExpr.accept(this); return null; } /** * */ public Object visitSchExpr(SchExpr schExpr) { //JOptionPane.showMessageDialog (null, "Visitou SchExpr"); SchText schText = schExpr.getSchText(); // TODO: Fix this gambi? Util.addNameTypeAnn(schText, NameType.StateComponent); // Visits the schema text schText.accept(this); return null; } /** * */ public Object visitApplExpr(ApplExpr applExpr) { Expr leftExpr = applExpr.getLeftExpr(); Expr rightExpr = applExpr.getRightExpr(); Boolean mixfix = applExpr.getMixfix(); if (leftExpr instanceof RefExpr) { String name = ((RefExpr)leftExpr).getZName().toString(); //if (!name.contains("+") && !name.contains("-") && !name.contains("*") && !name.contains("/")) { Util.addNameTypeAnn(leftExpr, NameType.ApplFunctName); //} } leftExpr.accept(this); rightExpr.accept(this); return null; } /** ************************************************************************************************************** * Util methods * *************************************************************************************************************** */ /** * Declare all the names in the signature in the current scope. */ private void defineSignature(Signature signature, NameType nameType) { ListTerm nameTypePairs = signature.getNameTypePair(); //[x: GIVEN SAM] for (int i = 0; i < nameTypePairs.size(); i++) { NameTypePair nameTypePair = (NameTypePair) nameTypePairs.get(i); //x : GIVEN SAM //DeclName declName = nameTypePair.getName(); //Angela's ZName declName = (ZName) nameTypePair.getName(); //Sam's CircusType circusType = (CircusType) nameTypePair.getType(); //GIVEN SAM _env.declareName(declName, nameType, circusType); } } /** * Declare in the environment some definitions of the mathematical toolkit. */ private void loadMathToolkit() { // \nat _env.declareName( //this._factory.createDeclName(MathToolkitConstants.NAT), //Angela's this._factory.createZName(MathToolkitConstants.NAT), //Sam's NameType.GlobalConstant, CircusType.createCircusInteger(), true); //addToTypeList _env.declareName( //this._factory.createDeclName(MathToolkitConstants.ADD), //Angela's this._factory.createZName(MathToolkitConstants.ADD), //Sam's NameType.GlobalConstant, CircusType.createCircusInteger()); //OBS: Daqui para baixo sempre haver� uma linha comentada por _env.declareName( //this._factory.createDeclName(MathToolkitConstants.SUB), this._factory.createZName(MathToolkitConstants.SUB), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.MULT), this._factory.createZName(MathToolkitConstants.MULT), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.DIV), this._factory.createZName(MathToolkitConstants.DIV), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.MOD), this._factory.createZName(MathToolkitConstants.MOD), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.LESS_EQUAL), this._factory.createZName(MathToolkitConstants.LESS_EQUAL), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.GREATER_EQUAL), this._factory.createZName(MathToolkitConstants.GREATER_EQUAL), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.LESS), this._factory.createZName(MathToolkitConstants.LESS), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.GREATER), this._factory.createZName(MathToolkitConstants.GREATER), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.NOTEQUAL), this._factory.createZName(MathToolkitConstants.NOTEQUAL), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.NUM_RANGE), this._factory.createZName(MathToolkitConstants.NUM_RANGE), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.PFUNCTION), this._factory.createZName(MathToolkitConstants.PFUNCTION), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.PINJECTION), this._factory.createZName(MathToolkitConstants.PINJECTION), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.EMPTYSET), this._factory.createZName(MathToolkitConstants.EMPTYSET), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.UNION), this._factory.createZName(MathToolkitConstants.UNION), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.CARDINALITY), this._factory.createZName(MathToolkitConstants.CARDINALITY), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.SUBSETEQ), this._factory.createZName(MathToolkitConstants.SUBSETEQ), NameType.GlobalConstant, CircusType.createCircusInteger()); _env.declareName( //this._factory.createDeclName(MathToolkitConstants.SET_DIFF), this._factory.createZName(MathToolkitConstants.SET_DIFF), NameType.GlobalConstant, CircusType.createCircusInteger()); } /*@Override public Object visitBasicChannelSetExpr(BasicChannelSetExpr arg0) { // TODO Auto-generated method stub return null; }*/ /*@Override public Object visitChannelSet(ChannelSet arg0) { // TODO Auto-generated method stub return arg0; }*/ @Override public Object visitOutputFieldAnn(OutputFieldAnn arg0) { // TODO Auto-generated method stub return null; } @Override public Object visitNarrPara(NarrPara arg0) { // TODO Auto-generated method stub return null; } }