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 Ast MacroParam(Expression expr)
 {
     if (expr is LambdaExpression)
     {
         return(ParseMacro(expr as LambdaExpression));
     }
     if (expr is ParameterExpression && Macro.IsMacroType(expr.Type))
     {
         return(MacroDefParam(expr as ParameterExpression));
     }
     else
     {
         return(Expr(ExtractMacros(expr, null)));
     }
 }