Example #1
0
        private static string GetParametersString(KBObject obj)
        {
            Tuple <int, string>         type_access;
            List <Tuple <int, string> > parameters     = new List <Tuple <int, string> >();
            ICallableObject             callableObject = obj as ICallableObject;

            foreach (Signature signature in callableObject.GetSignatures())
            {
                foreach (RuleDefinition.ParameterDefinition param in signature.Data.GetParameters())
                {
                    parameters.Add(new Tuple <int, string>(param.Type.DataType, param.AccessType.ToString()));
                }
            }
            string paramstring = "";

            parameters.Sort(Comparer <Tuple <int, string> > .Default);
            foreach (Tuple <int, string> parameter in parameters)
            {
                string accessor = "";
                if (parameter.Item2 == "PARM_IN")
                {
                    accessor = "I";
                }
                if (parameter.Item2 == "PARM_INOUT")
                {
                    accessor = "IO";
                }
                if (parameter.Item2 == "PARM_OUT")
                {
                    accessor = "O";
                }
                paramstring += accessor + ":" + parameter.Item1.ToString() + " ";
            }
            return(paramstring.TrimEnd());
        }
Example #2
0
	    public Boolean call(ICallableObject caller)
	    {
			// Loop over instructions
		    foreach (Instruction ins in this.instructions)
		    {
			    ins.call(this);
		    }
		    return true;
	    }
Example #3
0
 public override bool call(ICallableObject caller)
 {
     // Get the device.
     if (this.args.Length >= 3)
     {
         var device = this.cpu_ref.GetDevice(this.args[1]);
         Int64 flag = util.GetIntFromString(args[2]);
         device.flag((int)flag);
     }
     return false;
 }
Example #4
0
 public override bool call(ICallableObject caller)
 {
     // Get the top value off the stack.
     var top = this.cpu_ref.stack.Pop();
     // Push it back on, but incremented.
     if(top is Int16 || top is Int32 || top is Int64)
         this.cpu_ref.stack.Push(Convert.ToInt64(top) + 1);
     else if (top is Double || top is Single)
         this.cpu_ref.stack.Push((Double) top + 1);
     else return false;
     return true;
 }
Example #5
0
 public override bool call(ICallableObject caller)
 {
     // Pull two items off the stack.
     var item1 = this.cpu_ref.stack.Pop();
     var item2 = this.cpu_ref.stack.Pop();
     // Type check
     if (item1 is Int64 && item2 is Int64)
     {
         this.cpu_ref.stack.Push(Convert.ToInt64(item1) + Convert.ToInt64(item2));
         return true;
     }
     return false;
 }
Example #6
0
        private static int ParametersCountObject(KBObject obj)
        {
            int             countparm      = 0;
            ICallableObject callableObject = obj as ICallableObject;

            if (callableObject != null)
            {
                foreach (Signature signature in callableObject.GetSignatures())
                {
                    countparm = signature.ParametersCount;
                }
            }
            return(countparm);
        }
Example #7
0
        private static List <KBObject> GetObjectsWithProblems(List <KBObject> objs, IOutputService output)
        {
            int             numObj              = 0;
            int             objWithProblems     = 0;
            List <KBObject> objectsWithProblems = new List <KBObject>();

            foreach (KBObject obj in objs)
            {
                ICallableObject callableObject = obj as ICallableObject;

                if (callableObject != null)
                {
                    numObj += 1;
                    if ((numObj % 100) == 0)
                    {
                        output.AddLine("KBDoctor", "Processing " + obj.Name);
                    }
                    foreach (Signature signature in callableObject.GetSignatures())
                    {
                        Boolean someInOut = false;
                        foreach (Parameter parm in signature.Parameters)
                        {
                            if (parm.Accessor.ToString() == "PARM_INOUT")
                            {
                                someInOut = true;
                                break;
                            }
                        }
                        if (someInOut)
                        {
                            string ruleParm = Utility.ExtractRuleParm(obj);
                            if (ruleParm != "")
                            {
                                int countparms     = ruleParm.Split(new char[] { ',' }).Length;
                                int countsemicolon = ruleParm.Split(new char[] { ':' }).Length - 1;
                                if (countparms != countsemicolon)
                                {
                                    objWithProblems += 1;
                                    objectsWithProblems.Add(obj);
                                    OutputError err = new OutputError("Parameter without IN/OUT/INOUT ", MessageLevel.Error, new  KBObjectPosition(obj.Parts.Get <RulesPart>()));
                                    output.Add("KBDoctor", err);
                                }
                            }
                        }
                    }
                }
            }

            return(objectsWithProblems);
        }
Example #8
0
        private static void PrintNewRuleParm(KBDoctorXMLWriter writer, KBObject obj, string oldParm, string newParm)
        {
            ICallableObject callableObject = obj as ICallableObject;

            if (callableObject != null)
            {
                foreach (Signature signature in callableObject.GetSignatures())
                {
                    foreach (Parameter parm in signature.Parameters)
                    {
                        string nameParm = parm.IsAttribute ? parm.Name : "&" + parm.Name;
                        ListParmReferences(obj, nameParm, writer);
                    }
                }
            }
            writer.AddTableData(new string[] { Functions.linkObject(obj), oldParm, "====" });
            writer.AddTableData(new string[] { "", newParm, "=====" });
            writer.AddTableData(new string[] { "======", "======", "=======" });
        }
Example #9
0
        public static void MarkPublicObjects()
        {
            IKBService     kbserv  = UIServices.KB;
            IOutputService output  = CommonServices.Output;
            bool           success = true;
            string         title   = "KBDoctor - Mark Public Object";

            output.StartSection(title);
            string            outputFile = Functions.CreateOutputFile(kbserv, title);
            KBDoctorXMLWriter writer     = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Object", "Type", "Description", "Visibility" });

            MakeAllObjectPublic(kbserv, output);

            foreach (KBObject obj in kbserv.CurrentModel.Objects.GetAll())
            {
                output.AddLine("Object " + obj.Name);
                ICallableObject callableObject = obj as ICallableObject;
                if (((callableObject != null) || obj is ExternalObject || obj is SDT || obj is DataSelector) && (!(obj is Transaction)))
                {
                    ObjectVisibility objVisibility = obj.GetPropertyValue <ObjectVisibility>("ObjectVisibility");

                    ObjectVisibility newObjVisibility = RecoverVisibility(obj);

                    if (objVisibility != newObjVisibility)
                    {
                        obj.SetPropertyValue("ObjectVisibility", newObjVisibility);
                        Functions.SaveObject(output, obj);
                        string objNameLink = Functions.linkObject(obj);
                        writer.AddTableData(new string[] { objNameLink, obj.TypeDescriptor.Name, obj.Description, newObjVisibility.ToString() });
                        output.AddLine("....Change Object " + obj.Name);
                    }
                }
            }
            output.AddLine("");
            output.EndSection(title, success);
            writer.AddFooter();
            writer.Close();
            KBDoctorHelper.ShowKBDoctorResults(outputFile);
        }
Example #10
0
        public static bool ValidateINOUTinParm(KBObject obj)
        {
            bool            err            = false;
            ICallableObject callableObject = obj as ICallableObject;

            if (callableObject != null)
            {
                foreach (Signature signature in callableObject.GetSignatures())
                {
                    Boolean someInOut = false;
                    foreach (Parameter parm in signature.Parameters)
                    {
                        if (parm.Accessor.ToString() == "PARM_INOUT")
                        {
                            someInOut = true;
                            break;
                        }
                    }
                    if (someInOut)
                    {
                        RulesPart rulesPart = obj.Parts.Get <RulesPart>();

                        if (rulesPart != null)
                        {
                            Regex  myReg    = new Regex("//.*", RegexOptions.None);
                            Regex  paramReg = new Regex(@"parm\(.*\)", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
                            string reglas   = rulesPart.Source;
                            reglas = myReg.Replace(reglas, "");
                            Match match = paramReg.Match(reglas);
                            if (match != null)
                            {
                                int countparms     = match.ToString().Split(new char[] { ',' }).Length;
                                int countsemicolon = match.ToString().Split(new char[] { ':' }).Length - 1;
                                err = (countparms != countsemicolon);
                            }
                        }
                    }
                }
            }
            return(err);
        }
Example #11
0
        private static bool ValidateParms(KBObject obj)
        {
            bool result = true;
            // Object with parm() rule without in: out: or inout:
            IKBService      kbserv         = UIServices.KB;
            ICallableObject callableObject = obj as ICallableObject;

            if (callableObject != null)
            {
                foreach (Signature signature in callableObject.GetSignatures())
                {
                    Boolean someInOut = false;
                    foreach (Parameter parm in signature.Parameters)
                    {
                        if (parm.Accessor.ToString() == "PARM_INOUT")
                        {
                            someInOut = true;
                            break;
                        }
                    }
                    if (someInOut)
                    {
                        string ruleParm = Functions.ExtractRuleParm(obj);
                        if (ruleParm != "")
                        {
                            int countparms     = ruleParm.Split(new char[] { ',' }).Length;
                            int countsemicolon = ruleParm.Split(new char[] { ':' }).Length - 1;
                            if (countparms != countsemicolon)
                            {
                                string objNameLink = Functions.LinkObject(obj);

                                KBObjectCollection objColl = new KBObjectCollection();

                                result = false;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Example #12
0
 public override bool call(ICallableObject caller)
 {
     // Check the arguments.
     if (this.args.Length >= 2)
     {
         // Check type
         Object item;
         if (util.IsNumeric(this.args[1]))
         {
             item = Int64.Parse(this.args[1]);
         }
         else
         {
             item = this.args[1];
         }
         this.cpu_ref.stack.Push(item);
     }
     else
     {
         return false;
     }
     return true;
 }
Example #13
0
 public abstract bool call(ICallableObject caller);
Example #14
0
        internal static void GetClassesTypesWithTheSameSignature(IEnumerable <KBObject> objects, out HashSet <int> classes, out Hashtable[] Classes_types)
        {
            int MAX_PARAMS   = 512;
            int max_quantity = 0;

            classes = new HashSet <int>();
            List <KBObject>[] Classes_quantity = new List <KBObject> [MAX_PARAMS];

            //Divido el conjunto de objetos en clases determinadas por la cantidad de parametros (tomando en cuenta si son IN/OUT/INOUT).
            foreach (KBObject obj in objects)
            {
                ICallableObject callableObject = obj as ICallableObject;

                if (callableObject != null)
                {
                    foreach (Signature signature in callableObject.GetSignatures())
                    {
                        if (Classes_quantity[signature.ParametersCount] == null)
                        {
                            if (signature.ParametersCount > 0)
                            {
                                Classes_quantity[signature.ParametersCount] = new List <KBObject>();
                                classes.Add(signature.ParametersCount);
                                if (signature.ParametersCount > max_quantity)
                                {
                                    max_quantity = signature.ParametersCount;
                                }
                            }
                        }
                        if (signature.ParametersCount > 0)
                        {
                            Classes_quantity[signature.ParametersCount].Add(obj);
                        }
                    }
                }
            }

            //Divido el conjunto de objetos nuevamente por tipo de datos.
            Classes_types = new Hashtable[max_quantity];
            foreach (int i in classes)
            {
                Hashtable Class_type = new Hashtable();
                foreach (KBObject obj in Classes_quantity[i])
                {
                    string          paramstring = GetParametersString(obj);
                    List <KBObject> objects_list;
                    if (Class_type.ContainsKey(paramstring))
                    {
                        objects_list = Class_type[paramstring] as List <KBObject>;
                        objects_list.Add(obj);
                        Class_type[paramstring] = new List <KBObject>(objects_list);
                    }
                    else
                    {
                        objects_list = new List <KBObject>();
                        objects_list.Add(obj);
                        Class_type.Add(paramstring, new List <KBObject>(objects_list));
                    }
                }
                Classes_types[i - 1] = new Hashtable(Class_type);
            }
        }
Example #15
0
        internal static void RemoveObjectsNotCalled(KBModel kbmodel, IOutputService output, out List <string[]> lineswriter)
        {
            int    callers;
            string remove    = "";
            bool   continuar = true;

            lineswriter = new List <string[]>();
            do
            {
                continuar = false;
                foreach (KBObject obj in kbmodel.Objects.GetAll())
                {
                    ICallableObject callableObject = obj as ICallableObject;
                    if ((callableObject != null) | (obj is Artech.Genexus.Common.Objects.Attribute)
                        | obj is Artech.Genexus.Common.Objects.Table | obj is Domain | obj is ExternalObject | obj is Image | obj is SDT)
                    {
                        callers = 0;
                        foreach (EntityReference reference in obj.GetReferencesTo(LinkType.UsedObject))
                        {
                            callers = callers + 1;
                        }

                        if (callers == 0)
                        {
                            if ((obj is Transaction) | obj is Table | obj is Artech.Genexus.Common.Objects.Attribute | obj is Domain | obj is Image)
                            {
                                remove = "";
                            }
                            else
                            {
                                remove = "<a href=\"gx://?Command=fa2c542d-cd46-4df2-9317-bd5899a536eb;RemoveObject&guid=" + obj.Guid.ToString() + "\">Remove</a>";
                            }
                            string objNameLink    = Utility.linkObject(obj);
                            string isMainstr      = (Utility.isMain(obj) ? "Main" : string.Empty);
                            string isGeneratedstr = (Utility.isGenerated(obj) ? "Yes" : string.Empty);
                            if (!Utility.isMain(obj))
                            {
                                if (remove != "")
                                {
                                    try
                                    {
                                        obj.Delete();
                                        KBDoctorOutput.Message("REMOVING..." + obj.Name);
                                        remove      = "REMOVED!";
                                        objNameLink = obj.Name;
                                        continuar   = true;
                                    }
                                    catch (Exception e) { };
                                }
                                lineswriter.Add(new string[] { obj.TypeDescriptor.Name, objNameLink, remove, isGeneratedstr, isMainstr });
                            }
                            if ((obj is Transaction) && (obj.GetPropertyValue <bool>(Artech.Genexus.Common.Properties.TRN.GenerateObject)))
                            {
                                try
                                {
                                    obj.SetPropertyValue(Artech.Genexus.Common.Properties.TRN.GenerateObject, false);
                                    CleanObject(obj, output);
                                }
                                catch (Exception e) { };
                            }
                        }
                    }
                }
            } while (continuar);
        }
Example #16
0
        public static string ChangeRuleParmWithIN(KBObject obj)
        {
            string    newParm   = "";
            string    oldRules  = "";
            RulesPart rulesPart = obj.Parts.Get <RulesPart>();

            ICallableObject callableObject = obj as ICallableObject;

            if (callableObject != null)
            {
                foreach (Signature signature in callableObject.GetSignatures())
                {
                    Boolean someInOut = false;
                    foreach (Parameter parm in signature.Parameters)
                    {
                        if (parm.Accessor.ToString() == "PARM_INOUT")
                        {
                            someInOut = true;
                            break;
                        }
                    }
                    if (someInOut && (rulesPart != null))
                    {
                        Regex  myReg    = new Regex("//.*", RegexOptions.None);
                        Regex  myReg2   = new Regex(@"/\*.*\*/", RegexOptions.Singleline);
                        Regex  paramReg = new Regex(@"parm\(.*\)", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
                        string reglas   = rulesPart.Source;
                        reglas = myReg.Replace(reglas, "");
                        reglas = myReg2.Replace(reglas, "");

                        string reglas2 = reglas.Replace(Environment.NewLine, " ");

                        Match match = paramReg.Match(reglas2);


                        if (match != null)
                        {
                            int countparms     = match.ToString().Split(new char[] { ',' }).Length;
                            int countsemicolon = match.ToString().Split(new char[] { ':' }).Length - 1;
                            if (countparms != countsemicolon)
                            {
                                string objNameLink = Functions.linkObject(obj);

                                Regex coma = new Regex(",", RegexOptions.None);
                                newParm = coma.Replace(match.ToString(), ", IN:");

                                Regex inreg = new Regex("IN:", RegexOptions.IgnoreCase);
                                newParm = inreg.Replace(newParm, "IN:");

                                Regex outreg = new Regex("OUT:", RegexOptions.IgnoreCase);
                                newParm = outreg.Replace(newParm, "OUT:");

                                Regex IOreg = new Regex("INOUT:", RegexOptions.IgnoreCase);
                                newParm = IOreg.Replace(newParm, "INOUT:");


                                newParm = newParm.Replace(" ", "");
                                newParm = newParm.Replace("out:", "OUT:");
                                newParm = newParm.Replace("Out:", "OUT:");
                                newParm = newParm.Replace("InOut:", "INOUT:");
                                newParm = newParm.Replace("inout:", "INOUT:");
                                newParm = newParm.Replace("in:", "IN:");
                                newParm = newParm.Replace("In:", "IN:");
                                //---- CAMBIO REPETIDOS.
                                newParm = newParm.Replace("()", "##"); //Por los vectores

                                newParm = newParm.Replace("(", "(IN:");

                                newParm = newParm.Replace("IN:IN:", "IN:");
                                newParm = newParm.Replace("IN:OUT:", "OUT:");
                                newParm = newParm.Replace("IN:INOUT:", "INOUT:");
                                newParm = newParm.Replace("##", "()"); //Vuelvo el vector al original
                                newParm = newParm + ";";
                            }
                        }
                    }
                }
            }

            return(newParm);
        }
Example #17
0
 public override bool call(ICallableObject caller)
 {
     return true;
 }
Example #18
0
 public Variant(ICallableObject value)
 {
     Contract.Requires <ArgumentNullException>(value != null);
     this.type      = VariantType.Function;
     this.funcValue = value;
 }