Ejemplo n.º 1
0
 private static bool SetDefinition(Exprent expr, int index)
 {
     if (expr.type == Exprent.Exprent_Assignment)
     {
         Exprent left = ((AssignmentExprent)expr).GetLeft();
         if (left.type == Exprent.Exprent_Var)
         {
             VarExprent var = (VarExprent)left;
             if (var.GetIndex() == index)
             {
                 var.SetDefinition(true);
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        public virtual void SetVarDefinitions()
        {
            VarNamesCollector vc = varproc.GetVarNamesCollector();

            foreach (KeyValuePair <int, Statement> en in mapVarDefStatements)
            {
                Statement stat  = en.Value;
                int       index = en.Key;
                if (implDefVars.Contains(index))
                {
                    // already implicitly defined
                    continue;
                }
                varproc.SetVarName(new VarVersionPair(index, 0), vc.GetFreeName(index));
                // special case for
                if (stat.type == Statement.Type_Do)
                {
                    DoStatement dstat = (DoStatement)stat;
                    if (dstat.GetLooptype() == DoStatement.Loop_For)
                    {
                        if (dstat.GetInitExprent() != null && SetDefinition(dstat.GetInitExprent(), index
                                                                            ))
                        {
                            continue;
                        }
                        else
                        {
                            List <Exprent> lstSpecial = Sharpen.Arrays.AsList(dstat.GetConditionExprent(), dstat
                                                                              .GetIncExprent());
                            foreach (VarExprent var in GetAllVars(lstSpecial))
                            {
                                if (var.GetIndex() == index)
                                {
                                    stat = stat.GetParent();
                                    break;
                                }
                            }
                        }
                    }
                }
                Statement      first = FindFirstBlock(stat, index);
                List <Exprent> lst;
                if (first == null)
                {
                    lst = stat.GetVarDefinitions();
                }
                else if (first.GetExprents() == null)
                {
                    lst = first.GetVarDefinitions();
                }
                else
                {
                    lst = first.GetExprents();
                }
                bool defset = false;
                // search for the first assignment to var [index]
                int addindex = 0;
                foreach (Exprent expr in lst)
                {
                    if (SetDefinition(expr, index))
                    {
                        defset = true;
                        break;
                    }
                    else
                    {
                        bool foundvar = false;
                        foreach (Exprent exp in expr.GetAllExprents(true))
                        {
                            if (exp.type == Exprent.Exprent_Var && ((VarExprent)exp).GetIndex() == index)
                            {
                                foundvar = true;
                                break;
                            }
                        }
                        if (foundvar)
                        {
                            break;
                        }
                    }
                    addindex++;
                }
                if (!defset)
                {
                    VarExprent var = new VarExprent(index, varproc.GetVarType(new VarVersionPair(index
                                                                                                 , 0)), varproc);
                    var.SetDefinition(true);
                    lst.Add(addindex, var);
                }
            }
        }