예제 #1
0
        /// <summary>
        /// Compare definitions stored in SsaState with actual ones
        /// </summary>
        public void ValidateDefinitions(Action <string> error)
        {
            var dc         = new SsaDefinitionsCollector();
            var actualDefs = new Dictionary <Identifier, Statement>();

            foreach (var stm in Procedure.Statements)
            {
                var definitions = dc.CollectDefinitions(stm);
                foreach (var defId in definitions)
                {
                    if (actualDefs.TryGetValue(defId, out var def))
                    {
                        error(string.Format(
                                  "{0}: multiple definitions for {1} ({2} and {3})",
                                  Procedure.Name,
                                  defId,
                                  stm,
                                  def));
                    }
                    else
                    {
                        actualDefs.Add(defId, stm);
                    }
                }
            }
            foreach (var sid in Identifiers)
            {
                if (!actualDefs.TryGetValue(sid.Identifier, out var actualDef))
                {
                    actualDef = null;
                }
                if (sid.DefStatement != actualDef)
                {
                    error(string.Format(
                              "{0}: incorrect definition for {1}({2}). Should be {3}",
                              Procedure.Name,
                              sid.Identifier,
                              sid.DefStatement?.ToString() ?? "<null>",
                              actualDef?.ToString() ?? "<null>"));
                }
            }
            foreach (var defId in actualDefs.Keys)
            {
                if (!Identifiers.Contains(defId) &&
                    actualDefs.ContainsKey(defId))
                {
                    error(string.Format(
                              "{0}: there is no {1}({2}) in the ssa identifiers",
                              Procedure.Name,
                              defId,
                              actualDefs[defId]?.ToString() ?? "<null>"));
                }
            }
        }
예제 #2
0
        public void AddDefinitions(Statement stm)
        {
            var dc          = new SsaDefinitionsCollector();
            var definitions = dc.CollectDefinitions(stm);

            foreach (var id in definitions)
            {
                if (Identifiers.TryGetValue(id, out var sid))
                {
                    sid.DefExpression = null;
                    sid.DefStatement  = stm;
                }
            }
        }