Beispiel #1
0
        protected override void DoExpand(MacroContext context)
        {
            if (!context.CallerIsMacro())
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(Resources.Reference_can_only_be_used_in_a_macro_context, Alias),
                        context.Invocation.Position, MessageClasses.ReferenceUsage));
                return;
            }
            
            if (context.Invocation.Arguments.Count == 0)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(Resources.Reference_requires_at_least_one_argument, Alias),
                        context.Invocation.Position,
                        MessageClasses.ReferenceUsage));
                return;
            }

            var prototype = context.Invocation.Arguments[0] as AstExpand;
            if (prototype == null)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(Resources.Reference_requires_argument_to_be_a_prototype_of_a_macro_invocation, Alias),
                        context.Invocation.Position, MessageClasses.ReferenceUsage));
            }
            else
            {
                context.Block.Expression = _assembleImplCall(context, prototype.Entity.ToSymbolEntry(),
                                                             prototype.Position);
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Establishes macro context and parses arguments.
        /// </summary>
        /// <param name = "context">The macro context.</param>
        /// <returns>The call to call\macro\perform expression on success; null otherwise.</returns>
        private static AstGetSet _assembleCallPerform(MacroContext context)
        {
            if (context.Invocation.Arguments.Count == 0)
            {
                context.ReportMessage(
                    Message.Error(
                        Resources.CallMacro_call_macro_must_be_supplied_a_macro_reference, context.Invocation.Position,
                        MessageClasses.MacroReferenceForCallMacroMissing));
                return null;
            }

            if (!context.CallerIsMacro())
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(
                            Resources.CallMacro_CalledFromNonMacro,
                            context.Function.LogicalId), context.Invocation.Position,
                        MessageClasses.CallMacroCalledFromNonMacro));
                return null;
            }

            context.EstablishMacroContext();

            AstExpr call;
            AstExpr justEffect;
            AstExpr[] args;
            AstExpr macroSpec;

            if (!_parseArguments(context, out call, out justEffect, out args, out macroSpec))
                return null;

            // [| call\macro\prepare_macro($macroEntityRef, context, $call, $justEffect, $args...) |]
            return _prepareMacro(context, macroSpec, call, justEffect, args);
        }