Inheritance: MidMemberDecl, IMidMethodDecl
示例#1
0
 public MidExp MethodApp(
     SourceRange range,
     MidMethodDecl method,
     IEnumerable <MidVal> args)
 {
     return(_methodApps.Get(method).GetList(args).Cache(
                () => new MidMethodApp(range, method, args)));
 }
示例#2
0
 public MidMethodApp(
     SourceRange range,
     MidMethodDecl decl,
     IEnumerable <MidVal> args)
     : base(range, decl.ResultType)
 {
     _decl = decl;
     _args = args.ToArray();
 }
示例#3
0
 public MidMethodRef(
     MidMethodDecl decl,
     MidMemberTerm memberTerm,
     MidExpFactory exps)
 {
     _decl       = decl;
     _memberTerm = memberTerm;
     _exps       = exps;
 }
示例#4
0
 public void SimplifyMethod(MidMethodDecl method)
 {
     method.Body = SimplifyExp(method.Body, new SimplifyEnv(null));
 }
        public string GetMethod(MidMethodDecl method)
        {
            string result;
            if (_methods.TryGetValue(method, out result))
                return result;

            var name = _shared.GenerateName(method.Name.ToString());
            result = name;
            _methods[method] = result;

            Span span = new Span();

            span.WriteLine("void {0}(",
                name);

            bool firstParam = true;

            var resultType = EmitType(method.ResultType);
            var resultVar = DeclareOutParam(
                "__result",
                resultType,
                span,
                ref firstParam);

            foreach (var p in method.Parameters)
            {
                var pName = _shared.GenerateName(p.Name.ToString());

                var pType = EmitType(p.Type);
                var pVal = DeclareParam(
                    pName,
                    pType,
                    span,
                    ref firstParam);

                _varVals[p] = pVal;
            }

            span.WriteLine(")");
            span.WriteLine("{");

            var bodySpan = span.IndentSpan();

            // Scan for a label expression
            // along the 'spine' of the method

            var bodyExp = method.Body;
            while (bodyExp is MidLetExp)
            {
                bodyExp = ((MidLetExp)bodyExp).Body;
            }

            if (bodyExp is MidLabelExp)
            {
                var labelExp = (MidLabelExp)bodyExp;

                // a 'break' to this label should be
                // emitted as a 'return':

                _labels[labelExp.Label] = new ReturnLabel(this, resultVar);

                EmitExp(method.Body, bodySpan);
            }
            else
            {
                // Otherwise, the body is an expression,
                // and we should return it if it is non-null...
                var resultExp = EmitExp(method.Body, bodySpan);

                if (method.ResultType != null
                    && !(method.ResultType is MidVoidType))
                {
                    Assign(resultVar, resultExp, span);
                }
            }

            span.WriteLine("}");

            _subroutineHeaderSpan.Add(span);
            return result;
        }
 public void AddMethod(MidMethodDecl method)
 {
     _methods.Add(method);
 }
 public void SimplifyMethod(MidMethodDecl method)
 {
     method.Body = SimplifyExp(method.Body, new SimplifyEnv(null));
 }
示例#8
0
 public void AddMethod(MidMethodDecl method)
 {
     _methods.Add(method);
 }
示例#9
0
        private MidMemberDecl EmitMemberDeclImpl(
            IBuilder parent,
            IResMethodDecl resMethod,
            MidEmitEnv env)
        {
            var builtinTags = (from tag in resMethod.Line.Tags
                               let builtinTag = tag as ResBuiltinTag
                                                where builtinTag != null
                                                select builtinTag).ToArray();

            if (resMethod.Body != null)
            {
                // Don't use builtin version if there's an inline impl (probably
                // because its an override...)
                builtinTags = new ResBuiltinTag[] { };
            }


            IMidMethodDecl midMethod = null;

            if (builtinTags.Length != 0)
            {
                midMethod = new MidBuiltinMethodDecl(
                    parent,
                    resMethod.Name,
                    builtinTags);
            }
            else
            {
                midMethod = new MidMethodDecl(
                    parent,
                    resMethod.Name,
                    _exps);
            }

            midMethod.AddBuildAction(() =>
            {
                var resultType = EmitTypeExp(resMethod.ResultType, env);

                midMethod.ResultType = resultType;

                var midParams = (from p in resMethod.Parameters
                                 select new MidVar(p.Name, EmitTypeExp(p.Type, env))).ToArray();

                midMethod.Parameters = midParams;

                if (resMethod.Body != null && !IsCrossFrequencyMethod(resMethod))
                {
                    var paramEnv = new MidGlobalEmitEnv(env, env.Context);
                    foreach (var pair in midParams.Zip(resMethod.Parameters, Tuple.Create))
                    {
                        var midParam = pair.Item1;
                        var resParam = pair.Item2;

                        paramEnv.Insert(resParam, (SourceRange r) => new MidVarRef(r, midParam));
                    }

                    ((MidMethodDecl)midMethod).Body = EmitLocalExp(resMethod.Body, paramEnv);
                }
            });
            midMethod.DoneBuilding();

            if ((parent is MidFacetDecl) && (midMethod is MidMethodDecl))
            {
                ((MidFacetDecl)parent).AddMethod((MidMethodDecl)midMethod);
            }
            return((MidMemberDecl)midMethod);
        }
 public MidMethodRef(
     MidMethodDecl decl,
     MidMemberTerm memberTerm,
     MidExpFactory exps )
 {
     _decl = decl;
     _memberTerm = memberTerm;
     _exps = exps;
 }