Example #1
0
        internal Prototype(string name)
        {
            Name = name;

            var methods = BuiltInMethodManager.GetMethods(GetType());
            foreach (var methodData in methods)
            {
                var function = new SFunction(methodData.Delegate);
                var identifier = methodData.Name;

                function.FunctionUsage = methodData.Attribute.FunctionType;
                if (methodData.Attribute.FunctionType == FunctionUsageType.PropertyGetter)
                    identifier = PROPERTY_GET_PREFIX + identifier;
                else if (methodData.Attribute.FunctionType == FunctionUsageType.PropertySetter)
                    identifier = PROPERTY_SET_PREFIX + identifier;

                _prototypeMembers.Add(identifier, new PrototypeMember(
                        identifier: identifier,
                        data: function,
                        isStatic: methodData.Attribute.IsStatic,
                        isReadOnly: false,
                        isIndexerGet: methodData.Attribute.IsIndexerGet,
                        isIndexerSet: methodData.Attribute.IsIndexerSet
                    ));
            }
        }
Example #2
0
        internal Prototype(string name)
        {
            Name = name;

            var methods = BuiltInMethodManager.GetMethods(GetType());

            foreach (var methodData in methods)
            {
                var function   = new SFunction(methodData.Delegate);
                var identifier = methodData.Name;

                function.FunctionUsage = methodData.Attribute.FunctionType;
                if (methodData.Attribute.FunctionType == FunctionUsageType.PropertyGetter)
                {
                    identifier = PROPERTY_GET_PREFIX + identifier;
                }
                else if (methodData.Attribute.FunctionType == FunctionUsageType.PropertySetter)
                {
                    identifier = PROPERTY_SET_PREFIX + identifier;
                }

                _prototypeMembers.Add(identifier, new PrototypeMember(
                                          identifier: identifier,
                                          data: function,
                                          isStatic: methodData.Attribute.IsStatic,
                                          isReadOnly: false,
                                          isIndexerGet: methodData.Attribute.IsIndexerGet,
                                          isIndexerSet: methodData.Attribute.IsIndexerSet
                                          ));
            }
        }
 public DbsyncTvFunctionType(SFunction sff)
 {
     this.sf = sff;
     this.Text = sf.NazovFunkcie;
     this.typeOfIcon = FunctionIcon;
     this.Name = this.Text;
 }
Example #4
0
        /// <summary>
        /// Removes and returns the object at the beginning of the Queue.
        /// </summary>
        /// <param name="Function">The Function object.</param>
        /// <returns>The object that is removed from the beginning of the Queue.</returns>
        public SFunction Dequeue()
        {
            if (Function.Length == 0)
            {
                return(new SFunction());
            }

            // Clone will return data and after resize it
            SFunction returnData = new SFunction();

            Fill(ref returnData, ref Function[0]);

            if (Function.Length == 1)
            {
                Clear();
            }
            else
            {
                // Clone main data and after resize it
                SFunction[] newData = new SFunction[Function.Length - 1];

                for (int index = 1; index < Function.Length; index++)
                {
                    Fill(ref newData[index - 1], ref Function[index]);
                }

                Function = new SFunction[newData.Length];
                Function = (SFunction[])newData.Clone();
            }

            return(returnData);
        }
Example #5
0
 static void PrintInfo(SFunction sf, string bdt)
 {
     Console.WriteLine("----------------- Doc -----------------");
     if (sf != null)
     {
         sf(bdt);
     }
     Console.WriteLine("----------------- End -----------------");
 }
Example #6
0
        /// <summary>
        /// Determines whether an element is in the Queue.
        /// </summary>
        /// <param name="Function">The Function object.</param>
        /// <param name="target">The Object to locate in the Queue. The Function can be null.</param>
        /// <returns>true if obj is found in the Queue{ } otherwise, false.</returns>
        public bool Contain(SFunction target)
        {
            for (int index = 0; index < Function.Length; index++)
            {
                if (Function[index] == target)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #7
0
 private static object TranslateFunction(SFunction obj)
 {
     if (obj.Method != null)
     {
         return(obj.Method);
     }
     if (obj.DotNetMethod != null)
     {
         return(obj.DotNetMethod);
     }
     return(obj.ToScriptSource());
 }
Example #8
0
        static void Main(string[] args)
        {
            SFunction myDF;

            myDF  = PrintBD;
            myDF += PrintAge;
            PrintInfo(myDF, "1985-10-10");
            myDF -= PrintBD;
            PrintInfo(myDF, "1985-10-10");
            SFunction anaDF = null;

            PrintInfo(anaDF, "1983-04-15");
        }
Example #9
0
        /// <summary>
        /// Returns the object at the beginning of the Queue without removing it.
        /// </summary>
        /// <param name="Function">The Function object.</param>
        /// <returns>The object at the beginning of the Queue.</returns>
        public SFunction Peek()
        {
            if (Function.Length == 0)
            {
                return(new SFunction());
            }

            // Clone will return data and after resize it
            SFunction returnData = new SFunction();

            Fill(ref returnData, ref Function[0]);

            return(returnData);
        }
Example #10
0
        /// <summary>
        /// Adds an object to the end of the Queue.
        /// </summary>
        /// <param name="Function">The Function object.</param>
        /// <param name="target">The object to add to the Queue. The Function can be null.</param>
        public void Enqueue(SFunction target)
        {
            // Clone main data and after resize it
            SFunction[] newData = new SFunction[Function.Length + 1];
            Fill(ref newData[newData.Length - 1], ref target);

            if (Function.Length != 0)
            {
                for (int index = 0; index < Function.Length; index++)
                {
                    Fill(ref newData[index], ref Function[index]);
                }
            }

            Function = new SFunction[newData.Length];
            Function = (SFunction[])newData.Clone();
        }
Example #11
0
        private SObject ExecuteFunction(ScriptStatement statement)
        {
            // function <name> ()
            var exp = statement.Code;

            exp = exp.Remove(0, "function".Length).Trim();
            var functionName = exp.Remove(exp.IndexOf("(", StringComparison.Ordinal));

            if (!IsValidIdentifier(functionName))
            {
                return(ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxMissingVarName));
            }

            var functionExpression = "function " + exp.Remove(0, exp.IndexOf("(", StringComparison.Ordinal));

            // The function's body is the next statement:

            _index++;

            if (_index < _statements.Length)
            {
                var functionBodyStatement = _statements[_index];

                var functionBody = functionBodyStatement.Code;
                if (!functionBodyStatement.IsCompoundStatement)
                {
                    functionBody = "{" + functionBody + "}";
                }

                functionExpression += functionBody;

                var function = new SFunction(this, functionExpression);
                Context.AddVariable(functionName, function);

                return(function);
            }
            else
            {
                return(ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxExpectedExpression, "end of script"));
            }
        }
Example #12
0
        private SObject ExecuteFunction(ScriptStatement statement)
        {
            // function <name> ()
            var exp = statement.Code;

            exp = exp.Remove(0, "function".Length).Trim();
            var functionName = exp.Remove(exp.IndexOf("("));

            if (!IsValidIdentifier(functionName))
            {
                return(ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_MISSING_VAR_NAME));
            }

            var functionExpression = "function " + exp.Remove(0, exp.IndexOf("("));

            // The function's body is the next statement:

            _index++;

            if (_index < _statements.Length)
            {
                var functionBodyStatement = _statements[_index];

                var functionBody = functionBodyStatement.Code;
                if (!functionBodyStatement.IsCompoundStatement)
                {
                    functionBody = "{" + functionBody + "}";
                }

                functionExpression += functionBody;

                var function = new SFunction(this, functionExpression);
                Context.AddVariable(functionName, function);

                return(function);
            }
            else
            {
                return(ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_EXPECTED_EXPRESSION, "end of script"));
            }
        }
Example #13
0
        /// <summary>
        /// Khi người dùng click cấu hình
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_config_Click(object sender, EventArgs e)
        {
            DTO.DTOSql sqlDeltail = new DTO.DTOSql();
            sqlDeltail.AuthWin = dd_auth.selectedValue != TYPE_AUTH_SQL;
            sqlDeltail.Server  = cb_server.Text;
            sqlDeltail.DB      = cb_db.Text;
            sqlDeltail.User    = txb_user.Text;
            sqlDeltail.Pass    = txb_password.Text;

            SInvokeEvent cb = new SInvokeEvent(this);

            cb.Wait = (obj) =>
            {
                FGuest.showWaiting(true);
            };

            cb.Error = (obj) =>
            {
                SFunction.SetTimeOut(
                    () => {
                    Invoke((Action)(() => FGuest.showWaiting(false)));
                    MessageBox.Show("Cấu hình bị lỗi!");
                }
                    , 500);
            };

            cb.Success = (obj) =>
            {
                SFunction.SetTimeOut(
                    () => {
                    Invoke((Action)(() => FGuest.showWaiting(false)));
                    MessageBox.Show("Cấu hình thành công!");
                }
                    , 500);
            };

            busSql.Config(sqlDeltail, cb);
        }
        public DbSyncFunctionDiff(SFunction functionAin, SFunction functionBin)
        {
            this.functionA = functionAin;
            this.functionB = functionBin;

            functionAtributesA = new List<ObjectAtribute>();
            functionAtributesB = new List<ObjectAtribute>();

            privilegeDiffList = new List<DbSyncPrivilegeDiff>();

            grantsMissingDb1 = new List<Privilege>();
            grantsMissingDb2 = new List<Privilege>();
            grantsDifferent = new List<DbSyncPrivilegeDiff>();

            fulfillLists();

            ComparatorOfSQL compSQL;

            if (functionA == null || functionB == null)
            {
                if (functionA != null)
                {
                    functionName = functionA.NazovFunkcie;
                    functionAtributesA.Add(new ObjectAtribute("Name of function ",functionName, true));
                    functionAtributesA.Add(new ObjectAtribute("Sql text ", "Click button", true,true));
                    functionAtributesA.Add(new ObjectAtribute("Return type ", functionA.ReturnType, true));
                    compSQL = new ComparatorOfSQL(functionA.SqlText, null);
                    sqlTextListA = compSQL.TextA;
                    sqlTextListB = null;
                }
                if (functionB != null)
                {
                    functionName = functionB.NazovFunkcie;
                    functionAtributesB.Add(new ObjectAtribute("Name of function ", functionName, true));
                    functionAtributesB.Add(new ObjectAtribute("Sql text ", "Click button", true, true));
                    functionAtributesB.Add(new ObjectAtribute("Return type ", functionB.ReturnType, true));
                    compSQL = new ComparatorOfSQL(null, functionB.SqlText);
                    sqlTextListA = null;
                    sqlTextListB = compSQL.TextA;
                }
                else functionName = "UNDEFINED";

            }
            if (functionA != null && functionB != null)
            {
                compSQL = new ComparatorOfSQL(functionA.SqlText, functionB.SqlText);
                sqlTextListA = compSQL.TextA;
                sqlTextListB = compSQL.TextB;

                if (functionA.NazovFunkcie != functionB.NazovFunkcie) diffNAmeOfFunction = true;
                if (functionA.ReturnType != functionB.ReturnType) diffReturnType = true;
                if (compSQL.IsDifferent) diffSqlText = true;
                if (!ComparePrivileges(functionA.Privileges, functionB.Privileges)) diffPrivileges = true;

                if (diffNAmeOfFunction || diffPrivileges || diffReturnType || diffSqlText) different = true;
                else different = false;

                //vytvorim privileges
                foreach (Privilege privA in functionA.Privileges)
                {
                    bool found = false;
                    foreach (Privilege privB in functionB.Privileges)
                    {
                        if (privA.DBSyncCompareTO(privB))
                        {
                            found = true;
                            privilegeDiffList.Add(new DbSyncPrivilegeDiff(privA, privB));
                        }

                    }
                    if (!found) privilegeDiffList.Add(new DbSyncPrivilegeDiff(privA, null));
                }
                foreach (Privilege privB in functionB.Privileges)
                {
                    bool found = false;
                    foreach (DbSyncPrivilegeDiff priv in privilegeDiffList)
                    {
                        if (privB.getName() == priv.getName())
                        {
                            found = true;
                        }
                    }
                    if (!found) this.privilegeDiffList.Add(new DbSyncPrivilegeDiff(null, privB));
                }

                functionName = functionA.NazovFunkcie;
                functionAtributesA.Add(new ObjectAtribute("Name of function ", functionName, false));
                functionAtributesB.Add(new ObjectAtribute("Name of function ", functionName, false));

                if (diffSqlText)
                {
                    ObjectAtribute sqlA = new ObjectAtribute("Sql text ", "Click button", true, true);
                    functionAtributesA.Add(sqlA);
                    ObjectAtribute sqlB = new ObjectAtribute("Sql text  ", "Click button", true, true);
                    functionAtributesB.Add(sqlB);
                }
                else
                {
                    ObjectAtribute sql = new ObjectAtribute("Sql text  ", "Click button", false, true);
                    functionAtributesA.Add(sql);
                    functionAtributesB.Add(sql);
                }

                if (diffReturnType)
                {
                    ObjectAtribute sqlA = new ObjectAtribute("Return type ", functionA.ReturnType, true);
                    functionAtributesA.Add(sqlA);
                    ObjectAtribute sqlB = new ObjectAtribute("Return type  ", functionB.ReturnType, true);
                    functionAtributesB.Add(sqlB);
                }
                else
                {
                    ObjectAtribute sql = new ObjectAtribute("Return type  ", functionA.ReturnType, false);
                    functionAtributesA.Add(sql);
                    functionAtributesB.Add(sql);
                }

            }
            else different = true;
        }
Example #15
0
        public SObject Evaluate(SScope scope)
        {
            if(Children.Count == 0)
            {
                Int64 number;
                if (Int64.TryParse(Value, out number))
                    return number;
                else
                    return scope.Find(Value);
            }
            else
            {
                var first = Children[0].Value;
                if (first == "list")
                {
                    return new SList(this.Children.Skip(1).Select(exp => exp.Evaluate(scope)));
                }
                else if(first == "if")
                {
                    var condition = Children[1].Evaluate(scope) as SBool;
                    return condition ? Children[2].Evaluate(new SScope(scope)) :Children[3].Evaluate(new SScope(scope));
                }
                else if(first == "define")
                {
                    var child = Children[1];
                    if (child.Value == "(")
                    {
                        var funcName = child.Children[0].Value;
                        var body = Children[2];
                        var parameters = child.Children.Skip(1).Select(exp => exp.Value).ToArray();
                        var newScope = new SScope(scope);
                        var func = new SFunction(body, parameters, newScope);
                        return scope.Define(funcName,func);
                    }
                    return scope.Define(Children[1].Value, Children[2].Evaluate(scope));
                }
                else if (first == "set!")
                {
                    var variableName = Children[1].Value;
                    var newValue = Children[2];
                    if (scope.Find(variableName) != null)
                    {
                        return scope.Reset(variableName, newValue.Evaluate(scope));
                    }
                }
                else if(first == "begin")
                {
                    SObject result = null;
                    foreach (var statement in Children.Skip(1))
                        result = statement.Evaluate(scope);
                    return result;
                }
                else if (SScope.BuiltinFunctions.ContainsKey(first))
                {
                    var arguments = Children.Skip(1).ToArray();
                    return SScope.BuiltinFunctions[first](arguments, scope);
                }
                else
                {
                    var func = first == "(" ? /*High-order function*/Children[0].Evaluate(scope) as SFunction
                        : scope.Find(first) as SFunction;
                    var arguments = Children.Skip(1).Select(s => s.Evaluate(scope)).ToArray();
                    return func.Update(arguments).Evaluate();
                }
            }

            throw new Exception("Sorry!");
        }
Example #16
0
        /// <summary>
        /// Converts a string expression into a script object.
        /// </summary>
        private SObject ToScriptObject(string exp)
        {
            exp = exp.Trim();

            // This means it's either an indexer or an array
            if (exp.EndsWith("]"))
            {
                if (!(exp.StartsWith("[") && !exp.Remove(0, 1).Contains("["))) // When there's no "[" besides the start, and it starts with [, then it is an array. Otherwise, do real check.
                {
                    // It is possible that we are having a simple array declaration here.
                    // We check that by looking if we can find a "[" before the expression ends:

                    var depth                  = 0;
                    var index                  = exp.Length - 2;
                    var indexerStartIndex      = 0;
                    var foundIndexer           = false;
                    StringEscapeHelper escaper = new RightToLeftStringEscapeHelper(exp, index);

                    while (index > 0 && !foundIndexer)
                    {
                        var t = exp[index];
                        escaper.CheckStartAt(index);

                        if (!escaper.IsString)
                        {
                            if (t == ')' || t == '}' || t == ']')
                            {
                                depth++;
                            }
                            else if (t == '(' || t == '{')
                            {
                                depth--;
                            }
                            else if (t == '[')
                            {
                                if (depth == 0)
                                {
                                    if (index > 0)
                                    {
                                        indexerStartIndex = index;
                                        foundIndexer      = true;
                                    }
                                }
                                else
                                {
                                    depth--;
                                }
                            }
                        }

                        index--;
                    }

                    if (foundIndexer)
                    {
                        var indexerCode = exp.Substring(indexerStartIndex + 1, exp.Length - indexerStartIndex - 2);

                        var identifier = exp.Remove(indexerStartIndex);

                        var statementResult = ExecuteStatement(new ScriptStatement(indexerCode));
                        return(ToScriptObject(identifier).GetMember(this, statementResult, true));
                    }
                }
            }

            // Normal object return procedure:

            // Negative number:
            var isNegative = false;

            if (exp.StartsWith("-"))
            {
                exp        = exp.Remove(0, 1);
                isNegative = true;
            }

            double  dblResult;
            SObject returnObject;

            if (exp == SObject.LITERAL_NULL)
            {
                returnObject = Null;
            }
            else if (exp == SObject.LITERAL_UNDEFINED)
            {
                returnObject = Undefined;
            }
            else if (exp == SObject.LITERAL_BOOL_FALSE)
            {
                returnObject = CreateBool(false);
            }
            else if (exp == SObject.LITERAL_BOOL_TRUE)
            {
                returnObject = CreateBool(true);
            }
            else if (exp == SObject.LITERAL_NAN)
            {
                returnObject = CreateNumber(double.NaN);
            }
            else if (exp == SObject.LITERAL_THIS)
            {
                returnObject = Context.This;
            }
            else if (SNumber.TryParse(exp, out dblResult))
            {
                returnObject = CreateNumber(dblResult);
            }
            else if (exp.StartsWith("\"") && exp.EndsWith("\"") || exp.StartsWith("\'") && exp.EndsWith("\'"))
            {
                returnObject = CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 1), true, false);
            }
            else if (exp.StartsWith("$\"") && exp.EndsWith("\"") || exp.StartsWith("$\'") && exp.EndsWith("\'"))
            {
                returnObject = CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 2), true, true);
            }
            else if (exp.StartsWith("@\"") && exp.EndsWith("\"") || exp.StartsWith("@\'") && exp.EndsWith("\'"))
            {
                returnObject = CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 2), false, false);
            }
            else if (exp.StartsWith("{") && exp.EndsWith("}"))
            {
                returnObject = SProtoObject.Parse(this, exp);
            }
            else if (exp.StartsWith("[") && exp.EndsWith("]"))
            {
                returnObject = SArray.Parse(this, exp);
            }
            else if (exp.StartsWith("function") && Regex.IsMatch(exp, REGEX_FUNCTION))
            {
                returnObject = new SFunction(this, exp);
            }
            else if (Context.IsAPIUsing(exp))
            {
                returnObject = Context.GetAPIUsing(exp);
            }
            else if (Context.IsVariable(exp))
            {
                returnObject = Context.GetVariable(exp);
            }
            else if (Context.This.HasMember(this, exp))
            {
                returnObject = Context.This.GetMember(this, CreateString(exp), false);
            }
            else if (Context.IsPrototype(exp))
            {
                returnObject = Context.GetPrototype(exp);
            }
            else if (exp.StartsWith("new "))
            {
                returnObject = Context.CreateInstance(exp);
            }
            else if (exp.StartsWith(ObjectBuffer.OBJ_PREFIX))
            {
                var strId = exp.Remove(0, ObjectBuffer.OBJ_PREFIX.Length);
                var id    = 0;

                if (int.TryParse(strId, out id) && ObjectBuffer.HasObject(id))
                {
                    returnObject = (SObject)ObjectBuffer.GetObject(id);
                }
                else
                {
                    returnObject = ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_INVALID_TOKEN, exp);
                }
            }
            else
            {
                returnObject = ErrorHandler.ThrowError(ErrorType.ReferenceError, ErrorHandler.MESSAGE_REFERENCE_NOT_DEFINED, exp);
            }

            if (isNegative)
            {
                returnObject = ObjectOperators.NegateNumber(this, returnObject);
            }

            return(returnObject);
        }
Example #17
0
        private static PrototypeMember ParseFunctionStatement(ScriptProcessor processor, ScriptStatement headerStatement, ScriptStatement bodyStatement)
        {
            var header    = headerStatement.Code;
            var signature = header.Remove(header.IndexOf("(")).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            string identifier;
            var    isStatic     = false;
            var    isIndexerGet = false;
            var    isIndexerSet = false;
            var    functionType = FunctionUsageType.Default;

            var significantCount = 0;

            // Read static:
            if (signature.Contains(FUNCTION_SIGNATURE_STATIC))
            {
                isStatic = true;
                signature.Remove(FUNCTION_SIGNATURE_STATIC);
            }

            // Read indexer:
            if (signature.Contains(FUNCTION_SIGNATURE_INDEXER))
            {
                significantCount++;

                var indexerIndex = signature.IndexOf(FUNCTION_SIGNATURE_INDEXER);

                if (indexerIndex + 1 == signature.Count)
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_INDEXER_EXPECTED_TYPE);
                }

                var indexerType = signature[indexerIndex + 1];
                if (indexerType == FUNCTION_SIGNATURE_GET)
                {
                    isIndexerGet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else if (indexerType == FUNCTION_SIGNATURE_SET)
                {
                    isIndexerSet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_INDEXER_INVALID_TYPE, indexerType);
                }

                signature.Remove(FUNCTION_SIGNATURE_INDEXER);
            }
            // Read property:
            if (signature.Contains(FUNCTION_SIGNATURE_PROPERTY))
            {
                significantCount++;

                var propertyIndex = signature.IndexOf(FUNCTION_SIGNATURE_PROPERTY);

                if (propertyIndex + 1 == signature.Count)
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_PROPERTY_EXPECTED_TYPE);
                }

                var propertyType = signature[propertyIndex + 1];
                if (propertyType == FUNCTION_SIGNATURE_GET)
                {
                    functionType = FunctionUsageType.PropertyGetter;
                    signature.RemoveAt(propertyIndex + 1);
                }
                else if (propertyType == FUNCTION_SIGNATURE_SET)
                {
                    functionType = FunctionUsageType.PropertySetter;
                    signature.RemoveAt(propertyIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_PROPERTY_INVALID_TYPE, propertyType);
                }

                signature.Remove(FUNCTION_SIGNATURE_PROPERTY);
            }

            // Only one (or none) significant signature types can be added to a signature.
            if (significantCount > 1)
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_INCOMPATIBLE_SIGNATURE);
            }

            if (signature.Count != 2)
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_INVALID_FUNCTION_SIGNATURE);
            }

            identifier = signature[1];

            if (!ScriptProcessor.IsValidIdentifier(identifier))
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_MISSING_VAR_NAME);
            }

            // After the valid identifier check is done, we add the getter/setter prefix. It wouldn't pass the test.
            if (functionType == FunctionUsageType.PropertyGetter)
            {
                identifier = PROPERTY_GET_PREFIX + identifier;
            }
            if (functionType == FunctionUsageType.PropertySetter)
            {
                identifier = PROPERTY_SET_PREFIX + identifier;
            }

            var function = new SFunction(processor, signature[0] + " " + header.Remove(0, header.IndexOf("(")) + bodyStatement.Code)
            {
                FunctionUsage = functionType
            };

            return(new PrototypeMember(identifier, function, isStatic, false, isIndexerGet, isIndexerSet));
        }
 public override List<string> alterFunction(SFunction funkcIn)
 {
     List<string> output = new List<string>();
     output.Add("DROP FUNCTION [" + funkcIn.NazovFunkcie+"]");
     output.AddRange(createFunction(funkcIn));
     return output;
 }
Example #19
0
 /// <summary>
 /// Core of enqueue, fill a given source to given target.
 /// </summary>
 /// <param name="Function">The Function object.</param>
 /// <param name="target">The object will fill to target.</param>
 private void Fill(ref SFunction source, ref SFunction target)
 {
     source = new SFunction(target.Name, target.Request, target.Listen);
 }
Example #20
0
        private static PrototypeMember ParseFunctionStatement(ScriptProcessor processor, ScriptStatement headerStatement, ScriptStatement bodyStatement)
        {
            var header    = headerStatement.Code;
            var signature = header.Remove(header.IndexOf("(", StringComparison.Ordinal)).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            var isStatic     = false;
            var isIndexerGet = false;
            var isIndexerSet = false;
            var functionType = FunctionUsageType.Default;

            var significantCount = 0;

            // Read static:
            if (signature.Contains(FunctionSignatureStatic))
            {
                isStatic = true;
                signature.Remove(FunctionSignatureStatic);
            }

            // Read indexer:
            if (signature.Contains(FunctionSignatureIndexer))
            {
                significantCount++;

                var indexerIndex = signature.IndexOf(FunctionSignatureIndexer);

                if (indexerIndex + 1 == signature.Count)
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassFunctionIndexerExpectedType);
                }

                var indexerType = signature[indexerIndex + 1];
                if (indexerType == FunctionSignatureGet)
                {
                    isIndexerGet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else if (indexerType == FunctionSignatureSet)
                {
                    isIndexerSet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassFunctionIndexerInvalidType, indexerType);
                }

                signature.Remove(FunctionSignatureIndexer);
            }
            // Read property:
            if (signature.Contains(FunctionSignatureProperty))
            {
                significantCount++;

                var propertyIndex = signature.IndexOf(FunctionSignatureProperty);

                if (propertyIndex + 1 == signature.Count)
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassFunctionPropertyExpectedType);
                }

                var propertyType = signature[propertyIndex + 1];
                if (propertyType == FunctionSignatureGet)
                {
                    functionType = FunctionUsageType.PropertyGetter;
                    signature.RemoveAt(propertyIndex + 1);
                }
                else if (propertyType == FunctionSignatureSet)
                {
                    functionType = FunctionUsageType.PropertySetter;
                    signature.RemoveAt(propertyIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassFunctionPropertyInvalidType, propertyType);
                }

                signature.Remove(FunctionSignatureProperty);
            }

            // Only one (or none) significant signature types can be added to a signature.
            if (significantCount > 1)
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassIncompatibleSignature);
            }

            if (signature.Count != 2)
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassInvalidFunctionSignature);
            }

            var identifier = signature[1];

            if (!ScriptProcessor.IsValidIdentifier(identifier))
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxMissingVarName);
            }

            // After the valid identifier check is done, we add the getter/setter prefix. It wouldn't pass the test.
            if (functionType == FunctionUsageType.PropertyGetter)
            {
                identifier = PropertyGetPrefix + identifier;
            }
            if (functionType == FunctionUsageType.PropertySetter)
            {
                identifier = PropertySetPrefix + identifier;
            }

            var function = new SFunction(processor, signature[0] + " " + header.Remove(0, header.IndexOf("(", StringComparison.Ordinal)) + bodyStatement.Code)
            {
                FunctionUsage = functionType
            };

            return(new PrototypeMember(identifier, function, isStatic, false, isIndexerGet, isIndexerSet));
        }
        //nacitanie funkcii
        public override List<SFunction> ReadFunctions()
        {
            List<SFunction> funkcie = new List<SFunction>();
            SqlCommand com = pripojenie.CreateCommand();
            com.CommandText = "SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'";
            SqlDataReader red = com.ExecuteReader();
            while (red.Read())
            {
                SFunction sf = new SFunction();
                sf.NazovFunkcie = red["SPECIFIC_NAME"].ToString();
                sf.ReturnType = red["DATA_TYPE"].ToString();
                funkcie.Add(sf);

            }
            // nacitanie tela funkcii

            foreach (SFunction sf in funkcie )
            {
                SqlCommand com2 = pripojenie.CreateCommand();
                com2.CommandText = "sp_helptext";
                com2.CommandType = CommandType.StoredProcedure;
                com2.Parameters.Add(new SqlParameter("@objname", sf.NazovFunkcie));
                SqlDataReader red2 = com2.ExecuteReader();
                List<string> text = new List<string>();
                while (red2.Read())
                {
                    text.Add(red2["Text"].ToString());

                }
                red2.Close();
                sf.SqlText = text;
                // nacitanie grantov
                com2.CommandText = " SELECT " +
                                  " USER_NAME(dppriper.grantee_principal_id) AS [UserName], " +
                                  " dppri.type_desc AS principal_type_desc, " +
                                  " dppriper.class_desc, " +
                                  " OBJECT_NAME(dppriper.major_id) AS object_name, " +
                                  " dppriper.permission_name, " +
                                  " dppriper.state_desc AS permission_state_desc " +
                                  " FROM    sys.database_permissions dppriper " +
                                  " INNER JOIN sys.database_principals dppri " +
                                  " ON dppriper.grantee_principal_id = dppri.principal_id " +
                                  " where OBJECT_NAME(dppriper.major_id) = '" + sf.NazovFunkcie + "'";
                com2.CommandType = CommandType.Text;
                red2 = com2.ExecuteReader();
                while (red2.Read())
                {
                    Privilege priv = new Privilege();
                    priv.Grantee = red2["UserName"].ToString();
                    priv.Privilege_type = red2["permission_name"].ToString();
                    priv.Table_name = red2["object_name"].ToString();
                    sf.Privileges.Add(priv);
                }
            }

            return funkcie;
        }
 public override List<string> removeFunction(SFunction funkcIn)
 {
     List<string> output = new List<string>();
     output.Add("DROP FUNCTION [" + funkcIn.NazovFunkcie+"]");
     return output;
 }
Example #23
0
        private static PrototypeMember ParseFunctionStatement(ScriptProcessor processor, ScriptStatement statement)
        {
            string code = statement.Code;
            List<string> signature = code.Remove(code.IndexOf("(")).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            string identifier;
            bool isStatic = false;
            bool isIndexerGet = false;
            bool isIndexerSet = false;

            // Read static:
            if (signature.Contains(FUNCTION_SIGNATURE_STATIC))
            {
                isStatic = true;
                signature.Remove(FUNCTION_SIGNATURE_STATIC);
            }

            // Read indexer:
            if (signature.Contains(FUNCTION_SIGNATURE_INDEXER))
            {
                int indexerIndex = signature.IndexOf(FUNCTION_SIGNATURE_INDEXER);

                if (indexerIndex + 1 == signature.Count)
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_INDEXER_EXPECTED_TYPE);

                string indexerType = signature[indexerIndex + 1];
                if (indexerType == FUNCTION_SIGNATURE_GET)
                {
                    isIndexerGet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else if (indexerType == FUNCTION_SIGNATURE_SET)
                {
                    isIndexerSet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_INDEXER_INVALID_TYPE, new object[] { indexerType });
                }

                signature.Remove(FUNCTION_SIGNATURE_INDEXER);
            }

            if (signature.Count != 2)
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_INVALID_FUNCTION_SIGNATURE);

            identifier = signature[1];

            if (!ScriptProcessor.IsValidIdentifier(identifier))
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_MISSING_VAR_NAME);

            SFunction function = new SFunction(processor, signature[0] + code.Remove(0, code.IndexOf("(")));

            return new PrototypeMember(identifier, function, isStatic, false, isIndexerGet, isIndexerSet);
        }
 public abstract List<string> removeFunction(SFunction funkcIn);
 //scripts to modify objects
 public abstract List<string> alterFunction(SFunction funkcIn);
        public override List<string> createFunction(SFunction funkcIn)
        {
            List<string> output = new List<string>();
            string proctext = "";
            foreach (string s in funkcIn.SqlText)
            {
                proctext += s;
            }
            output.Add(proctext);

            foreach (Privilege priv in funkcIn.Privileges)
            {
                output.Add(createPrivilege(priv));
            }

            return output;
        }
 public override List<string> alterFunction(SFunction funkcIn)
 {
     throw new NotImplementedException();
 }
Example #28
0
        private static PrototypeMember ParseFunctionStatement(ScriptProcessor processor, ScriptStatement headerStatement, ScriptStatement bodyStatement)
        {
            var header = headerStatement.Code;
            var signature = header.Remove(header.IndexOf("(")).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            string identifier;
            var isStatic = false;
            var isIndexerGet = false;
            var isIndexerSet = false;
            var functionType = FunctionUsageType.Default;

            var significantCount = 0;

            // Read static:
            if (signature.Contains(FUNCTION_SIGNATURE_STATIC))
            {
                isStatic = true;
                signature.Remove(FUNCTION_SIGNATURE_STATIC);
            }

            // Read indexer:
            if (signature.Contains(FUNCTION_SIGNATURE_INDEXER))
            {
                significantCount++;

                var indexerIndex = signature.IndexOf(FUNCTION_SIGNATURE_INDEXER);

                if (indexerIndex + 1 == signature.Count)
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_INDEXER_EXPECTED_TYPE);

                var indexerType = signature[indexerIndex + 1];
                if (indexerType == FUNCTION_SIGNATURE_GET)
                {
                    isIndexerGet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else if (indexerType == FUNCTION_SIGNATURE_SET)
                {
                    isIndexerSet = true;
                    signature.RemoveAt(indexerIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_INDEXER_INVALID_TYPE, indexerType);
                }

                signature.Remove(FUNCTION_SIGNATURE_INDEXER);
            }
            // Read property:
            if (signature.Contains(FUNCTION_SIGNATURE_PROPERTY))
            {
                significantCount++;

                var propertyIndex = signature.IndexOf(FUNCTION_SIGNATURE_PROPERTY);

                if (propertyIndex + 1 == signature.Count)
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_PROPERTY_EXPECTED_TYPE);

                var propertyType = signature[propertyIndex + 1];
                if (propertyType == FUNCTION_SIGNATURE_GET)
                {
                    functionType = FunctionUsageType.PropertyGetter;
                    signature.RemoveAt(propertyIndex + 1);
                }
                else if (propertyType == FUNCTION_SIGNATURE_SET)
                {
                    functionType = FunctionUsageType.PropertySetter;
                    signature.RemoveAt(propertyIndex + 1);
                }
                else
                {
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_FUNCTION_PROPERTY_INVALID_TYPE, propertyType);
                }

                signature.Remove(FUNCTION_SIGNATURE_PROPERTY);
            }

            // Only one (or none) significant signature types can be added to a signature.
            if (significantCount > 1)
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_INCOMPATIBLE_SIGNATURE);

            if (signature.Count != 2)
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_CLASS_INVALID_FUNCTION_SIGNATURE);

            identifier = signature[1];

            if (!ScriptProcessor.IsValidIdentifier(identifier))
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_MISSING_VAR_NAME);

            // After the valid identifier check is done, we add the getter/setter prefix. It wouldn't pass the test.
            if (functionType == FunctionUsageType.PropertyGetter)
                identifier = PROPERTY_GET_PREFIX + identifier;
            if (functionType == FunctionUsageType.PropertySetter)
                identifier = PROPERTY_SET_PREFIX + identifier;

            var function = new SFunction(processor, signature[0] + " " + header.Remove(0, header.IndexOf("(")) + bodyStatement.Code)
            {
                FunctionUsage = functionType
            };

            return new PrototypeMember(identifier, function, isStatic, false, isIndexerGet, isIndexerSet);
        }
 public SPrimitive(SFunction f, bool fac, int ac, bool preEval = true)
 {
     func = f; fixedArgCount = fac; argCount = ac; this.preEval = preEval;
 }
 public abstract List<string> createFunction(SFunction funkcIn);