Esempio n. 1
0
        /// <summary>
        /// Declare a user PHP function.
        /// </summary>
        /// <param name="routine">Routine to be declared. Its index is initialized lazily.</param>
        public void DeclarePhpRoutine(RoutineInfo routine)
        {
            Debug.Assert(routine != null);

            int index = routine.Index;

            if (index == 0)
            {
                index = s_nameToIndex.GetOrAdd(routine.Name, newname =>
                {
                    return(s_contextRoutinesCounter.GetNewIndex());
                });

                if (index < 0)
                {
                    // redeclaring over app context function
                    RedeclarationError(routine.Name);
                }

                //
                routine.Index = index;
            }

            Debug.Assert(routine.Index > 0);

            //
            if (_contextRoutines.Length < index)
            {
                Array.Resize(ref _contextRoutines, index * 2);
            }

            DeclarePhpRoutine(ref _contextRoutines[index - 1], routine);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines if the routine is entirely public.
        /// </summary>
        public static bool IsPublic(this RoutineInfo /*!*/ routine)
        {
            var methods = routine.Methods;

            for (int i = 0; i < methods.Length; i++)
            {
                if (!methods[i].IsPublic)
                {
                    return(false);
                }
            }
            return(true);    // all methods are public
        }
Esempio n. 3
0
 void DeclarePhpRoutine(ref RoutineInfo slot, RoutineInfo routine)
 {
     if (object.ReferenceEquals(slot, null))
     {
         slot = routine;
     }
     else
     {
         if (!object.ReferenceEquals(slot, routine))
         {
             _redeclarationCallback(routine);
         }
     }
 }
Esempio n. 4
0
 void DeclarePhpRoutine(ref RoutineInfo slot, RoutineInfo routine)
 {
     if (ReferenceEquals(slot, null))
     {
         slot = routine;
     }
     else
     {
         if (!ReferenceEquals(slot, routine))
         {
             RedeclarationError(routine);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Declare a user PHP function.
        /// </summary>
        /// <param name="routine">Routine to be declared. Its index is initialized lazily.</param>
        public void DeclarePhpRoutine(RoutineInfo routine)
        {
            Debug.Assert(routine != null);

            int index = routine.Index;

            if (index == 0)
            {
                lock (_nameToIndex)
                {
                    if (_nameToIndex.TryGetValue(routine.Name, out index))
                    {
                        if (index < 0)  // redeclaring over an app context function
                        {
                            _redeclarationCallback(routine);
                        }
                    }
                    else
                    {
                        index = _contextRoutinesCounter.GetNewIndex() + 1;
                        _nameToIndex[routine.Name] = index;
                    }
                }

                //
                routine.Index = index;
            }

            Debug.Assert(routine.Index > 0);

            //
            if (_contextRoutines.Length < index)
            {
                Array.Resize(ref _contextRoutines, index * 2);
            }

            DeclarePhpRoutine(ref _contextRoutines[index - 1], routine);
        }
Esempio n. 6
0
 /// <summary>
 /// Checks whether given routine is declared in current context.
 /// </summary>
 internal bool IsDeclared(RoutineInfo routine)
 {
     return(routine.Index > 0 && routine.Index <= _contextRoutines.Length && _contextRoutines[routine.Index - 1] == routine);
 }
Esempio n. 7
0
 static void RedeclarationError(RoutineInfo routine)
 {
     // TODO: ErrCode & throw
     throw new InvalidOperationException($"Function {routine.Name} redeclared!");
 }
Esempio n. 8
0
 /// <summary>
 /// Checks whether given routine is declared in current context.
 /// </summary>
 internal bool IsDeclared(RoutineInfo routine)
 {
     return (routine.Index > 0 && routine.Index <= _contextRoutines.Length && _contextRoutines[routine.Index - 1] == routine);
 }
Esempio n. 9
0
 void DeclarePhpRoutine(ref RoutineInfo slot, RoutineInfo routine)
 {
     if (object.ReferenceEquals(slot, null))
     {
         slot = routine;
     }
     else
     {
         if (!object.ReferenceEquals(slot, routine))
         {
             _redeclarationCallback(routine);
         }
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Declare a user PHP function.
        /// </summary>
        /// <param name="routine">Routine to be declared. Its index is initialized lazily.</param>
        public void DeclarePhpRoutine(RoutineInfo routine)
        {
            Debug.Assert(routine != null);

            int index = routine.Index;
            if (index == 0)
            {
                lock (_nameToIndex)
                {
                    if (_nameToIndex.TryGetValue(routine.Name, out index))
                    {
                        if (index < 0)  // redeclaring over an app context function
                        {
                            _redeclarationCallback(routine);
                        }
                    }
                    else
                    {
                        index = _contextRoutinesCounter.GetNewIndex() + 1;
                        _nameToIndex[routine.Name] = index;
                    }
                }

                //
                routine.Index = index;
            }

            Debug.Assert(routine.Index > 0);

            //
            if (_contextRoutines.Length < index)
            {
                Array.Resize(ref _contextRoutines, index * 2);                
            }

            DeclarePhpRoutine(ref _contextRoutines[index - 1], routine);
        }