コード例 #1
0
ファイル: MacroSession.cs プロジェクト: SealedSun/prx
            private void _implementMergeRules(MacroContext context, AstExpr ce,
                                              IEnumerable<AstNode> fs, AstExpr fe)
            {
                var contextBlock = context.Block;
                //cs  is already stored in contextBlock, 
                //  the rules position cs always at the beginning, thus no need to handle cs.

                //At this point
                //  {   ce   }  iff (ce ∧ fs ∧ fe)
                //  {tmp = ce}  iff (ce ∧ fs ∧ ¬fe)
                //  {        }  otherwise
                if (ce != null && fs != null)
                {
                    if (fe != null)
                    {
                        contextBlock.Add(ce);
                    }
                    else
                    {
                        //Might at a later point become a warning
                        var invocationPosition = context.Invocation.Position;
                        context.ReportMessage(Message.Create(MessageSeverity.Info,
                                                             String.Format(
                                                                 Resources.MacroFunctionExpander__UsedTemporaryVariable,
                                                                 HumanId),
                                                             invocationPosition, MessageClasses.BlockMergingUsesVariable));

                        var tmpV = context.AllocateTemporaryVariable();

                        //Generate assignment to temporary variable
                        var tmpVRef = context.Factory.Reference(invocationPosition, EntityRef.Variable.Local.Create(tmpV));
                        var assignTmpV = context.Factory.IndirectCall(invocationPosition,tmpVRef,PCall.Set);
                        assignTmpV.Arguments.Add(ce);
                        contextBlock.Add(assignTmpV);

                        //Generate lookup of computed value
                        ce = context.Factory.IndirectCall(invocationPosition,tmpVRef);
                    }
                }

                //At this point
                //  {fs}    iff (fs)
                //  {  }    otherwise

                if (fs != null)
                {
                    foreach (var stmt in fs)
                        contextBlock.Add(stmt);
                }

                //Finally determine expression
                //  = fe    iff (ce ∧ fe)
                //  = ce    iff (ce ∧ ¬fe ∧ ¬fs)
                //  = tmp   iff (ce ∧ ¬fe ∧ fs)
                //  = ⊥     otherwise
                if (fe != null)
                    contextBlock.Expression = fe;
                else if (ce != null)
                    contextBlock.Expression = ce; //if tmp is involved, it has replaced ce
                else
                    contextBlock.Expression = null; //macro session will cover this case
            }
コード例 #2
0
ファイル: MacroSession.cs プロジェクト: SealedSun/prx
        private static void _reportException(MacroContext context, IMacroExpander expander,
            Exception e)
        {
            context.ReportMessage(Message.Create(MessageSeverity.Error,
                String.Format(
                    Resources.MacroSession_ExceptionDuringExpansionOfMacro,
                    expander.HumanId, context.Function.LogicalId,
                    e.Message), context.Invocation.Position, MessageClasses.ExceptionDuringCompilation));
#if DEBUG
            Console.WriteLine(e);
#endif
        }
コード例 #3
0
ファイル: MacroSession.cs プロジェクト: SealedSun/prx
            public bool TryExpandPartially(CompilerTarget target, MacroContext context)
            {
                if (!MacroFunction.Meta[PartialMacroKey].Switch)
                    return false;

                var successRaw = _invokeMacroFunction(target, context);
                if (successRaw.Type != PType.Bool)
                {
                    context.ReportMessage(Message.Create(MessageSeverity.Error,
                                                         Resources.MacroFunctionExpander_PartialMacroMustIndicateSuccessWithBoolean,
                                                         context.Invocation.Position,
                                                         MessageClasses.PartialMacroMustReturnBoolean));
                    _setupDefaultExpression(context);
                    return false;
                }

                return (bool) successRaw.Value;
            }