Esempio n. 1
0
        private void CheckForUndeclaredIdent(ASTProgram root, CheckerInformation info)
        {
            UsedIdents usedIdents = new UsedIdents(info);

            root.GetUsedIdents(usedIdents);
            info.CurrentNamespace = null;
            //Check to see if each local outflow parameter was initialized
            foreach (string ident in info.ProcFuncs)
            {
                foreach (ASTParam param in info.ProcFuncs[ident].Params)
                {
                    if (param.FlowMode == FlowMode.OUT && (!usedIdents.LocalInitialized.ContainsKey(ident) || !usedIdents.LocalInitialized[ident].Contains(param.Ident)))
                    {
                        throw new CheckerException("The outflow parameter '" + param.Ident + "' of the procedure/function '" + ident + "' was not initialized");
                    }
                }
            }
            //Check if each global outflow parameter was initialized
            foreach (string global in info.Globals)
            {
                if (info.Globals[global] is ASTParam)
                {
                    ASTParam param = (ASTParam)info.Globals[global];
                    if (param.FlowMode == FlowMode.OUT && !usedIdents.GlobalInitialized.Contains(param.Ident))
                    {
                        throw new CheckerException("The global outflow parameter '" + param.Ident + "' of the program was not initialized");
                    }
                }
            }
        }
Esempio n. 2
0
            /// <summary>
            /// Fork used identifier for the usage in an if/else command.
            /// </summary>
            /// <returns>2nd instance of this class which is a deep copies of this instance</returns>
            public UsedIdents ForkForIf()
            {
                UsedIdents b = new UsedIdents(info);

                b.AllowInit = this.AllowInit;
                this.GlobalInitialized.ForEach(g => b.GlobalInitialized.Add(g));
                foreach (var element in this.LocalInitialized)
                {
                    b.LocalInitialized.Add(element.Key, new List <string>());
                    element.Value.ForEach(l => b.LocalInitialized[element.Key].Add(l));
                }
                return(b);
            }
Esempio n. 3
0
            /// <summary>
            /// Merges previously forked UserIdents.
            /// Throws an exception if the UserIdents are not compatible.
            /// </summary>
            /// <param name="b"></param>
            public void MergeForIf(UsedIdents b)
            {
                CheckerException ifException = new CheckerException("Not both branches of the if/else command initialize the same identifiers");

                if (this.GlobalInitialized.Count != b.GlobalInitialized.Count)
                {
                    throw ifException;
                }
                if (this.LocalInitialized.Count != b.LocalInitialized.Count)
                {
                    throw ifException;
                }
                foreach (string global in this.GlobalInitialized)
                {
                    if (!b.GlobalInitialized.Contains(global))
                    {
                        throw ifException;
                    }
                }
                foreach (var local in this.LocalInitialized)
                {
                    if (!b.LocalInitialized.ContainsKey(local.Key))
                    {
                        throw ifException;
                    }
                    if (local.Value.Count != b.LocalInitialized[local.Key].Count)
                    {
                        throw ifException;
                    }
                    foreach (string localIdent in local.Value)
                    {
                        if (!b.LocalInitialized[local.Key].Contains(localIdent))
                        {
                            throw ifException;
                        }
                    }
                }
            }