Exemple #1
0
            /// <summary>
            /// Ensures unique constant ID for given constant name.
            /// Gets positive ID for runtime constant, negative ID for application constant.
            /// IDs are indexed from <c>1</c>. Zero is invalid ID.
            /// </summary>
            static int RegisterConstantId(string name, bool ignoreCase = false, bool appConstant = false)
            {
                var cname = new ConstName(name, ignoreCase);
                int idx;

                s_rwLock.EnterUpgradeableReadLock();
                try
                {
                    if (!s_map.TryGetValue(cname, out idx))
                    {
                        s_rwLock.EnterWriteLock();
                        try
                        {
                            // new constant ID, non zero
                            idx = appConstant
                                ? -(++s_countApp)    // app constants are negative
                                : (++s_countCtx);    //

                            s_map.Add(cname, idx);
                        }
                        finally
                        {
                            s_rwLock.ExitWriteLock();
                        }
                    }
                }
                finally
                {
                    s_rwLock.ExitUpgradeableReadLock();
                }

                //
                return(idx);
            }
Exemple #2
0
        /// <summary>
        /// Returns DEEP COPY of a 'real' compiled constant.
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        public Expression GetCompiledConstValue(Expression exp)
        {
            Expression content = (Expression)exp.CreateCopy();
            MoveInfo   expTree = new MoveInfo(content, SearchTree.ContentTree, 0, _sf);
            IElement   curElem = expTree.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (curElem != null)
            {
                if (curElem is FuncCall)
                {
                    ((FuncCall)curElem).Compile_SpecifyPath(this);
                }
                else if (curElem is DelegateDef)
                {
                    ((DelegateDef)curElem).Compile_SpecifyPath(this);
                }
                else if (curElem is ConstName)
                {
                    ConstName constName = (ConstName)curElem;
                    IElement  finalExp  = null;

                    OverwriteConstDef overwriteConst = OverwriteConstDefList.Find(a => a.ConstInfo.Compare(constName.ConstInfo));
                    if (overwriteConst != null)
                    {
                        finalExp = overwriteConst.OriginalContent;
                    }
                    else
                    {
                        ConstInfo targetConstInfo = constName.ConstInfo;
                        if (targetConstInfo.SF.SI.IsGlobal)
                        {
                            finalExp = GetGlobalConstContent(constName);
                        }
                        else
                        {
                            finalExp = GetCompiledConstValue(targetConstInfo);
                        }
                    }

                    expTree.ReplaceCurrent(finalExp);
                }
                else if (curElem is UsingName)
                {
                    UsingName usingName   = (UsingName)curElem;
                    string    finalSFPath = GetActualSFPath(usingName.UsingInfo.SFPath);
                    expTree.ReplaceCurrent(new Path(usingName.UsingInfo.SFPath, finalSFPath));
                }
                else if (curElem is Path)
                {
                    string originalPath = ((Path)curElem).OriginalPath;
                    string finalSFPath  = GetActualSFPath(originalPath);
                    ((Path)curElem).Update(finalSFPath);
                }

                curElem = expTree.FindNextBlack(SearchDirection.LeftToRight);
            }
            return(content);
        }
Exemple #3
0
 private IElement GetGlobalConstContent(ConstName constName)
 {
     if (constName.ConstInfo.SF.SFPath == "compiler")
     {
         return(constName);
     }
     else
     {
         return(constName.ConstInfo.Value);
     }
 }
        private double CalcConst(ConstName constName, double parameterPr, double parameterVci, double parameterVr, double parameterVco)
        {
            switch (constName)
            {
            case ConstName.A:
                return(1 / Math.Pow(parameterVci - parameterVr, 2) * (parameterVci * (parameterVci + parameterVr) - 4 * parameterVci * parameterVr * Math.Pow((parameterVci + parameterVr) / (2 * parameterVr), 3)));

            case ConstName.B:
                return(1 / Math.Pow(parameterVci - parameterVr, 2) * (4 * (parameterVci + parameterVr) * Math.Pow((parameterVci + parameterVr) / (2 * parameterVr), 3) - (3 * parameterVci + parameterVr)));

            case ConstName.C:
                return(1 / Math.Pow(parameterVci - parameterVr, 2) * (2 - 4 * Math.Pow((parameterVci + parameterVr) / (2 * parameterVr), 3)));

            default:
                return(0);
            }
        }
Exemple #5
0
            /// <summary>
            /// Ensures unique constant ID for given constant name.
            /// Gets positive ID for runtime constant, negative ID for application constant.
            /// IDs are indexed from <c>1</c>. Zero is invalid ID.
            /// </summary>
            static int RegisterConstantId(string name, bool ignorecase = false, bool appConstant = false)
            {
                var cname = new ConstName(name, ignorecase);
                int idx;

                if (!_map.TryGetValue(cname, out idx))
                {
                    // TODO: W lock

                    // new constant ID, non zero
                    idx = appConstant
                        ? -(++_countApp)    // app constants are negative
                        : (++_countCtx);    //

                    _map.Add(cname, idx);
                }

                //
                return(idx);
            }
Exemple #6
0
        public bool CompileMembers()
        {
            // replace usings & paths & constants & specify paths in constants
            foreach (ConstDef c in ConstDefList)
            {
                c.ReplaceMembersInContent(this);
            }

            foreach (OverwriteConstDef c in OverwriteConstDefList)
            {
                c.ReplaceMembersInContent(this);
            }

            // replace path in includes
            foreach (PreProcessorInclude i in IncludeDefList)
            {
                string originalPath = i.Path.OriginalPath;
                string finalPath    = GetActualSFPath(originalPath);
                i.Path.Update(finalPath);
            }

            // update constants in overwritten SFs
            foreach (OverwriteConstDef c in OverwriteConstDefList)
            {
                ScriptFile overwriteSF    = _overwriteSFList[c.ConstInfo.SF];
                ConstInfo  cInOverwriteSF = overwriteSF.SI.FindLocalConst(c.ConstInfo.Name);
                cInOverwriteSF.ConstDef.OriginalContent = c.CompiledContent;
            }

            // compile overwritten SFs
            foreach (ScriptFile originalSF in _overwriteSFList.Keys)
            {
                ScriptFile sf = _overwriteSFList[originalSF];
                if (sf == _sf) // ignore itself
                {
                    continue;
                }

                if (!sf.PrepareCompileSC())
                {
                    return(false);
                }

                if (!sf.CompileMembersSC())
                {
                    return(false);
                }

                sf.CompileCodeSC();
                sf.CompileOutputSC();
            }

            // replace usings & paths & constants in code
            MoveInfo treeInfo = new MoveInfo(this, SearchTree.ChildrenTree, 0, this._sf);
            IElement curElem  = treeInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (curElem != null)
            {
                if (curElem is UsingName)
                {
                    UsingName usingName   = (UsingName)curElem;
                    string    finalSFPath = GetActualSFPath(usingName.UsingInfo.SFPath);
                    treeInfo.ReplaceCurrent(new Path(usingName.UsingInfo.SFPath, finalSFPath));
                }
                else if (curElem is Path)
                {
                    string originalPath = ((Path)curElem).OriginalPath;
                    string finalSFPath  = GetActualSFPath(originalPath);
                    ((Path)curElem).Update(finalSFPath);
                }
                else if (curElem is ConstName)
                {
                    ConstName constName = (ConstName)curElem;
                    IElement  finalExp  = null;

                    OverwriteConstDef overwriteConst = OverwriteConstDefList.Find(a => a.ConstInfo.Compare(constName.ConstInfo));
                    if (overwriteConst != null)
                    {
                        finalExp = overwriteConst.OriginalContent;
                    }
                    else
                    {
                        ConstInfo targetConstInfo = constName.ConstInfo;
                        if (targetConstInfo.SF.SI.IsGlobal)
                        {
                            finalExp = GetGlobalConstContent(constName);
                        }
                        else
                        {
                            finalExp = GetCompiledConstValue(targetConstInfo);
                        }
                    }

                    treeInfo.ReplaceCurrent(finalExp);
                }

                curElem = treeInfo.FindNextBlack(SearchDirection.LeftToRight);
            }
            return(true);
        }
Exemple #7
0
 public SelfConstRef(ConstName name)
 {
     Name = name;
 }