/// <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); }
/// <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 }
void DeclarePhpRoutine(ref RoutineInfo slot, RoutineInfo routine) { if (object.ReferenceEquals(slot, null)) { slot = routine; } else { if (!object.ReferenceEquals(slot, routine)) { _redeclarationCallback(routine); } } }
void DeclarePhpRoutine(ref RoutineInfo slot, RoutineInfo routine) { if (ReferenceEquals(slot, null)) { slot = routine; } else { if (!ReferenceEquals(slot, routine)) { RedeclarationError(routine); } } }
/// <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); }
/// <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); }
static void RedeclarationError(RoutineInfo routine) { // TODO: ErrCode & throw throw new InvalidOperationException($"Function {routine.Name} redeclared!"); }
/// <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); }