Exemple #1
0
 /// <summary>
 ///     Creates a new macro context in the specified macro session.
 /// </summary>
 /// <param name = "session">The macro expansion session.</param>
 /// <param name = "invocation">The node that is being expanded.</param>
 /// <param name = "isJustEffect">Whether the nodes return value will be discarded by the surrounding program.</param>
 internal MacroContext(MacroSession session, AstGetSet invocation, bool isJustEffect)
 {
     if (session == null)
         throw new ArgumentNullException("session");
     if (invocation == null)
         throw new ArgumentNullException("invocation");
     _isJustEffect = isJustEffect;
     _invocation = invocation;
     _session = session;
     _block = new AstScopedBlock(invocation.Position, session.CurrentBlock);
     _isPartialApplication = _invocation.Arguments.Any(AstPartiallyApplicable.IsPlaceholder);
     _sentinelBlock = session.Target.CurrentBlock;
 }
Exemple #2
0
 /// <summary>
 ///     Returns the current macro session, or creates one if necessary. Must always be paired with a call to <see
 ///      cref = "ReleaseMacroSession" />. Do not call <see cref = "MacroSession.Dispose" />.
 /// </summary>
 /// <returns>The current macro session.</returns>
 public MacroSession AcquireMacroSession()
 {
     _macroSessionReferenceCounter++;
     Debug.Assert(_macroSessionReferenceCounter > 0);
     return _macroSession ?? (_macroSession = new MacroSession(this));
 }
Exemple #3
0
        /// <summary>
        ///     Releases the macro session acquired via <see cref = "AcquireMacroSession" />. Will dispose of the session, if no other release is pending.
        /// </summary>
        /// <param name = "acquiredSession">A session previously acquired through <see cref = "AcquireMacroSession" />.</param>
// ReSharper disable UnusedParameter.Global
        public void ReleaseMacroSession(MacroSession acquiredSession)
// ReSharper restore UnusedParameter.Global
        {
            if (_macroSession != acquiredSession)
                throw new InvalidOperationException(
                    "Invalid call to CompilerTarget.ReleaseMacroSession. Trying to release macro session that doesn't match.");
            _macroSessionReferenceCounter--;
            if (_macroSessionReferenceCounter <= 0)
            {
                _macroSession.Dispose();
                _macroSession = null;
            }

            Debug.Assert(_macroSessionReferenceCounter >= 0);
            Debug.Assert(_macroSessionReferenceCounter == 0 || _macroSession != null);
        }