Ejemplo n.º 1
0
        private MidExp EmitExpImpl(
            ResBaseExp exp,
            MidEmitEnv env)
        {
            var inheritedDecls = env.InheritedDecls;

            if (inheritedDecls == null)
            {
                throw new NotImplementedException();
            }

            var inheritedDeclsArr = inheritedDecls.ToArray();

            var firstDecl = inheritedDeclsArr[0];

            if (firstDecl.Init == null)
            {
                throw new NotImplementedException();
            }

            var nestedEnv = new MidDummyEmitEnv(env);

            nestedEnv.InheritedDecls = inheritedDeclsArr.Skip(1);

            return(EmitExpRaw(
                       firstDecl.Init,
                       nestedEnv));
        }
Ejemplo n.º 2
0
        private MidExp EmitExpImpl(ResMethodApp resApp, MidEmitEnv env)
        {
            var resMethod = resApp.Method;

            if (IsCrossFrequencyMethod(resMethod))
            {
                var resBody = resMethod.Body;
                if (resBody != null)
                {
                    var bindEnv = new MidDummyEmitEnv(env);
//                    var bindEnv = new MidLocalEmitEnv(
//                        env,
//                        _identifiers,
//                        null,
//                        _exps );

                    BindForMemberTerm(resMethod.MemberTerm, bindEnv);

                    foreach (var p in resApp.Args.Zip(resMethod.Parameters, Tuple.Create))
                    {
                        var resArg   = p.Item1;
                        var resParam = p.Item2.Decl;

                        var paramElement = GetFreq(resApp.Type, bindEnv);
                        if (resParam.Type is ResFreqQualType)
                        {
                            var resParamType = (ResFreqQualType)resParam.Type;
                            var resParamFreq = (MidElementType)EmitTypeExp(resParamType.Freq, bindEnv);
                            paramElement = resParamFreq.Decl;
                        }

                        var argVal = EmitValToElement(resArg, paramElement, bindEnv);

                        // insert value into env...
                        bindEnv.Insert(resParam, (SourceRange r) => argVal);
                    }

                    return(EmitVal(resBody, bindEnv));
//                    return bindEnv.Wrap(EmitVal(resBody, bindEnv));
                }
            }

            var methodRef = EmitMemberTerm(resMethod.MemberTerm, env);
            var args      = from a in resApp.Args
                            select EmitVal(a, env);

            return(methodRef.App(resApp.Range, args));
        }
Ejemplo n.º 3
0
        private MidMemberDecl EmitMemberDeclImpl(
            MidFacetDecl midFacet,
            IResAttributeDecl resAttrib,
            MidEmitEnv env)
        {
            var midAttrWrap = new MidAttributeWrapperDecl(midFacet, resAttrib.Name, resAttrib.Range);

            midAttrWrap.AddBuildAction(() =>
            {
                var fqType = resAttrib.Type;
                var freq   = fqType.Freq;
                var type   = fqType.Type;

                var midElement = (MidElementDecl)midFacet.Pipeline.LookupMemberDecl(freq.MemberTerm.Decl);
                var midType    = EmitTypeExp(type, env);

                MidAttributeDecl midAttr = null;
                if (resAttrib.Init == null)
                {
                    midAttr = new MidAttributeDecl(
                        resAttrib.Name,
                        midElement,
                        midType,
                        null);
                    midElement.AddAttribute(midAttr);
                    if (resAttrib.Line.ConcretenessMode == ResMemberConcretenessMode.Abstract)
                    {
                        midAttr.IsAbstract = true;
                    }
                    else if (resAttrib.IsInput())
                    {
                        midAttr.IsInput = true;
                    }
                    else if (resAttrib.IsOptional())
                    {
                        midAttr.IsOptional = true;
                    }
                    else if (resAttrib.Line.Tags.Any((t) => t is ResBuiltinTag))
                    {
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    // Eventually:
//                    else
//                        midAttr.IsInput = true;
                }
                else
                {
                    var initEnv = new MidDummyEmitEnv(env);

                    var inheritedDecls = resAttrib.Line.InheritedDecls;
                    if (inheritedDecls != null)
                    {
                        // Skip first decl if we are already using an inherited decl:
                        if (resAttrib.Line.MemberDeclMode != ResMemberDeclMode.Inherited)
                        {
                            initEnv.InheritedDecls = inheritedDecls.Cast <IResAttributeDecl>();
                        }
                        else
                        {
                            initEnv.InheritedDecls = inheritedDecls.Cast <IResAttributeDecl>().Skip(1);
                        }
                    }

                    var midExp = EmitAttrExp(midElement, midType, resAttrib.Init, initEnv);

                    if (midExp is MidAttributeRef &&
                        ((MidAttributeRef)midExp).Decl.IsOptional)
                    {
                        midAttr = ((MidAttributeRef)midExp).Decl;
                    }
                    else if (resAttrib.IsOutput())
                    {
                        midAttr = new MidAttributeDecl(
                            resAttrib.Name,
                            midElement,
                            midType,
                            midExp);
                        midElement.AddAttribute(midAttr);
                    }
                    else
                    {
                        midAttr = midElement.CacheAttr(midExp, midType);
                        midAttr.TrySetName(resAttrib.Name, resAttrib.Range);
                    }
                }
                if (resAttrib.IsOutput() && !midAttr.IsOptional)
                {
                    midAttr.IsForcedOutput = true;
                }

                midAttrWrap.Attribute = midAttr;
                midElement.AddAttributeWrapper(midAttrWrap);
            });
            midAttrWrap.DoneBuilding();

            midFacet.AddAttribute(midAttrWrap);
            return(midAttrWrap);

            /*
             *
             * var midAttrib = new MidAttributeDecl(midFacet, resAttrib.Name);
             *
             * if (resAttrib.Line.ConcretenessMode == ResMemberConcretenessMode.Abstract)
             *  midAttrib.IsAbstract = true;
             *
             * if( resAttrib.IsOutput )
             *  midAttrib.IsOutput = true;
             *
             * midAttrib.AddBuildAction(() =>
             * {
             *  var fqType = resAttrib.Type;
             *  var freq = fqType.Freq;
             *  var type = fqType.Type;
             *
             *  var midElement = (MidElementDecl)midFacet.Pipeline.LookupMemberDecl(freq.MemberTerm.Decl);
             *
             *  midAttrib.Type = EmitTypeExp(resAttrib.Type, env);
             *
             *  if (resAttrib.Init != null)
             *  {
             *      var savedElement = _currentElement;
             *      _currentElement = midElement;
             *
             *      midAttrib.Exp = EmitLocalExp(resAttrib.Init, env);
             *
             *      _currentElement = savedElement;
             *  }
             *
             *  midAttrib.Element = midElement;
             *  midElement.AddAttribute(midAttrib);
             * });
             *
             * midAttrib.DoneBuilding();
             *
             * midFacet.AddAttribute(midAttrib);
             * return midAttrib;
             * */
        }