Exemple #1
0
        /// <summary>
        /// To Perform the static analysis on a single definition first.
        /// </summary>
        public void StaticAnalysis()
        {
            MustAbstract = Process.MustBeAbstracted();
            Channels     = Process.GetChannels();
            GlobalVars   = Process.GetGlobalVariables();

            if (AlphabetEvents != null)
            {
                if (AlphabetEvents.ContainsVariable())
                {
                    AlphabetsCalculable = false;
                    Alphabets           = null;
                }
                else
                {
                    Alphabets           = new HashSet <string>(new EventCollection(AlphabetEvents).EventNames);
                    AlphabetsCalculable = true;
                }
            }
            else
            {
                if (AlphabetsCalculable)
                {
                    //to check why is null here? forget the reason le.
                    Alphabets = Process.GetAlphabets(null);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// To Perform the static analysis on a single definition first.
 /// </summary>
 public void StaticAnalysis()
 {
     if (AlphabetEvents != null)
     {
         if (AlphabetEvents.ContainsVariable())
         {
             AlphabetsCalculable = false;
             Alphabets           = null;
         }
         else
         {
             Alphabets           = new HashSet <string>(new EventCollection(AlphabetEvents).EventNames);
             AlphabetsCalculable = true;
         }
     }
     else
     {
         if (AlphabetsCalculable)
         {
             Alphabets = GetAlphabets(null);
         }
     }
 }
Exemple #3
0
        public override HashSet <string> GetAlphabets(Dictionary <string, string> visitedDefinitionRefs)
        {
            if (visitedDefinitionRefs == null)
            {
                return(new HashSet <string>());
            }

            if (Specification.CollectDataOperationEvent == null)
            {
                if (Def.AlphabetsCalculable)
                {
                    return(new HashSet <string>(Def.Alphabets));
                }

                //if the alphabet is defined manually.
                if (Def.AlphabetEvents != null)
                {
                    Dictionary <string, Expression> newMapping = new Dictionary <string, Expression>();
                    for (int i = 0; i < Args.Length; i++)
                    {
                        string key = Def.Parameters[i];
                        newMapping.Add(key, Args[i]);
                    }

                    EventCollection evtcoll = Def.AlphabetEvents.ClearConstant(newMapping);

                    if (!evtcoll.ContainsVariable())
                    {
                        return(new HashSet <string>(evtcoll.EventNames));
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("ERROR - PAT FAILED to calculate the alphabet of process " + Name + ".");
                        sb.AppendLine("CAUSE - Process " + Name + " is invoked with gloabl variables as parameters!");
                        sb.AppendLine(
                            "REMEDY - 1) Avoid passing global variable as parameters  2) Or manually specify the alphabet of process " +
                            Name +
                            " using the following syntax: \n\r\t #alphabet " + Name +
                            " {X}; \n\rwhere X is a set of event names with no variables.");
                        throw new RuntimeException(sb.ToString());
                    }
                }

                //if the arguments contain variable (global variable), then throw an exception to say we can't calculate the alphabet.
                foreach (var arg in Args)
                {
                    if (arg.HasVar)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("ERROR - PAT FAILED to calculate the alphabet of process " + Name + ".");
                        sb.AppendLine("CAUSE - Process " + Name +
                                      " is invoked with gloabl variables as parameters!");
                        sb.AppendLine("REMEDY - Manually specify the alphabet of process " + Name +
                                      " using the following syntax: \n\r\t #alphabet " + Name +
                                      " {X}; \n\rwhere X is a set of events.");
                        throw new RuntimeException(sb.ToString());
                    }
                }
            }

            string idString = Name + "(";

            for (int i = 0; i < Args.Length; i++)
            {
                Expression exp = Args[i];
                idString += exp.ToString();
                if (i < Args.Length - 1)
                {
                    idString += ",";
                }
            }

            idString += ")";

            if (Specification.CollectDataOperationEvent == null)
            {
                if (visitedDefinitionRefs.ContainsKey(Name))
                {
                    if (visitedDefinitionRefs[Name] != idString)
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.AppendLine("ERROR - PAT FAILED to calculate the alphabet of process " + Name + ".");
                        sb.AppendLine("CAUSE - Process " + Name + " is recursively invoked with different parameters!");
                        sb.AppendLine("REMEDY - Manually specify the alphabet of process " + Name +
                                      " using the following syntax: \n\r\t #alphabet " + Name +
                                      " {X}; \n\rwhere X is a set of events.");
                        throw new RuntimeException(sb.ToString());
                    }
                    else
                    {
                        return(new HashSet <string>());
                    }
                }
                else
                {
                    Dictionary <string, string> newVisitedDef = new Dictionary <string, string>();

                    foreach (string var in visitedDefinitionRefs.Keys)
                    {
                        newVisitedDef.Add(var, visitedDefinitionRefs[var]);
                    }

                    newVisitedDef.Add(Name, idString);

                    return(GetProcess(null).GetAlphabets(newVisitedDef));
                }
            }
            else
            {
                if (visitedDefinitionRefs.ContainsKey(Name))
                {
                    return(new HashSet <string>());
                }
                else
                {
                    Dictionary <string, string> newVisitedDef = new Dictionary <string, string>();

                    foreach (string var in visitedDefinitionRefs.Keys)
                    {
                        newVisitedDef.Add(var, visitedDefinitionRefs[var]);
                    }

                    newVisitedDef.Add(Name, idString);

                    return(Def.Process.GetAlphabets(newVisitedDef));
                }
            }
        }