Exemple #1
0
        protected Expression ExtractMacro(InvocationExpression ie, Expression rootExpression,
                                          Ast.Variable resultVar)
        {
            Ast.MacroDefinition macro = null;
            var me = ie.Expression.CastExpr <MemberExpression> (ExpressionType.MemberAccess);

            if (me != null)
            {
                InitializeMacro(me.Member);
                var mac = Macro.Get(me.Member);
                if (!Macro.IsMacroType(me.Type) || mac == null)
                {
                    return(ie);
                }
                AddExternalReferences(mac.Program, mac.TypesDefined);
                macro = mac.AstMacro;
            }
            else
            {
                var pe = ie.Expression.CastExpr <ParameterExpression> (ExpressionType.Parameter);
                if (pe == null || !Macro.IsMacroType(pe.Type))
                {
                    return(ie);
                }
                macro = MacroDefParam(pe);
            }
            if (ie != rootExpression || resultVar == null)
            {
                resultVar = Macro.GenUniqueVar(macro.Result.Type, "res");
            }
            _currentScope.DeclareLocal(resultVar, null);
            _currentScope.CodeOut(Ast.MCall(macro, resultVar, ie.Arguments.Select(MacroParam)));
            return(Expression.Parameter(ie.Type, resultVar.Name));
        }
Exemple #2
0
        protected void MacroBody(Ast.MacroDefinition definition, Expression expr)
        {
            var node = expr.CastExpr <MethodCallExpression> (ExpressionType.Call);

            _currentScope.CodeOut(Ast.Ass(Ast.VRef(definition.Result),
                                          Expr(ExtractMacros(
                                                   node != null && node.Method.IsEvaluate(_linqType) ?
                                                   ParseLinqExpression(node.Arguments[0]) :
                                                   expr, null))));
        }